PHP 表单未在 MySQL 中插入数据 [英] PHP Forms not inserting data in MySQL

查看:34
本文介绍了PHP 表单未在 MySQL 中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将数据保存到表中,我在名为 Register.php 的文件中有以下代码,我启用了 error_reporting 以查看任何错误,但没有显示任何错误.我的数据库称为注册,表称为用户,托管在 GoDaddy 上

<?phpif(isset($_Post['注册'])) {session_start();$FName = $_POST['First_Name'];$LName = $_POST['Last_Name'];$用户名 = $_POST['用户名'];$Email = $_POST['Email'];$PW = $_POST['密码'];$sql = $con->query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('{$Fname}', '{$LName}', '{$Username}', '{$Email}', '{$PW}')");}?><!doctype html><头><meta http-equiv='Content-Type' content='text/html;字符集=utf-8'/><link href="Style/Master.css" rel="stylesheet" type="text/css"/><title>注册</title><身体><form action="" method="post" name="RegisterForm" id="RegisterForm"><div class="FormElement"><input name="First_Name" type="text" required="required" class="TField" id="First_Name" placeholder="First Name">

<div class="FormElement"><input name="Last_Name" type="text" required="required" class="TField" id="Last_Name" placeholder="Last Name">

<div class="FormElement"><input name="Username" type="text" required="required" class="TField" id="Username" placeholder="Username">

<div class="FormElement"><input name="Email" type="text" required="required" class="TField" id="Email" placeholder="Email">

<div class="FormElement"><input name="Password" type="text" required="required" class="TField" id="Password" placeholder="Password">

<div class="FormElement"><input name="Register" type="submit" class="button" id="Register" placeholder="Register">

</html>

这是Connections.php中的代码,只是没有我的真实用户名和密码

任何帮助将不胜感激!

解决方案

您需要编辑 Connection.php

mysql_connect("localhost", "USERNAME", "PASSWORD");mysql_select_db("注册");//你的数据库名称

而且你还必须编辑

 mysql_query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')") 或死(mysql_error());

I'm having trouble with data not saving to a table, I've got the following code in a file called Register.php, I have enabled error_reporting to see any errors, but none are showing. My database is called Registration and the table is called users and is being hosted on GoDaddy

<?php
require 'Connections/Connections.php';
?>

<?php
if(isset($_Post['Register'])) {

    session_start();
    $FName = $_POST['First_Name'];
    $LName = $_POST['Last_Name'];
    $Username = $_POST['Username'];
    $Email = $_POST['Email'];
    $PW = $_POST['Password'];

    $sql = $con->query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('{$Fname}', '{$LName}', '{$Username}', '{$Email}', '{$PW}')");

}
?>

<!doctype html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<link href="Style/Master.css" rel="stylesheet" type="text/css" />
<title>Register</title>
</head>
<body>
<form action="" method="post" name="RegisterForm" id="RegisterForm">

    <div class="FormElement">
        <input name="First_Name" type="text" required="required"    class="TField" id="First_Name" placeholder="First Name">
    </div>

    <div class="FormElement">
        <input name="Last_Name" type="text" required="required" class="TField" id="Last_Name" placeholder="Last Name">
    </div>

    <div class="FormElement">
        <input name="Username" type="text" required="required" class="TField" id="Username" placeholder="Username">
    </div>

    <div class="FormElement">
        <input name="Email" type="text" required="required" class="TField"   id="Email" placeholder="Email">
    </div>

    <div class="FormElement">
        <input name="Password" type="text" required="required" class="TField" id="Password" placeholder="Password">
    </div>

    <div class="FormElement">
        <input name="Register" type="submit" class="button" id="Register"        placeholder="Register">
    </div>
</body>
</html>

This is the code in the Connections.php just without my real username and password

<?php

$con = mysql_connect("localhost", "USERNAME", "PASSWORD", "Registration");

?>

Any help would be very much appreciated!

解决方案

You need to edit the Connection.php

mysql_connect("localhost", "USERNAME", "PASSWORD"); 
mysql_select_db("Registration");  //your data base name

And also you have to edit

 mysql_query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')") or die(mysql_error());

这篇关于PHP 表单未在 MySQL 中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆