我尝试了很多不同的事情,并且进行了很多搜索,但都没有解决方案。我正在尝试使用html表单将数据提交到sql表。
这是我的register.php文件的代码。
$con = mysqli_connect("localhost", "database_name", "password" "database_user"); if($con === false) { die("ERROR Could not Connect." . mysqli_connect_error()); } $lasty= mysqli_real_escape_string($_POST['laz']); $namez=mysqli_real_escape_string($_POST['namer']); $emailAddr=mysqli_real_escape_string($_POST['emaila']); $userName=mysqli_real_escape_string($_POST['usrn']); $passwo=mysqli_real_escape_string($_POST['passw']); $sqql = "INSERT INTO 'database_name' . table' (UserID, FirstName, LastName, Email, UserName, Password) VALUES (NULL, '$namez', '$lasty', '$emailAddr', '$userName', '$passwo')"; if (mysqli_query($con, $sqql)) { echo "Successfull"; } else { echo "Did not work!" . $con->error; } mysqli_close($con);
我的HTML文件是:
<form action="register.php" method="POST"> First Name: <input type="text" name="namer" placeholder="First Name"/> <br> Last Name: <input type='text' name='laz' /> <br> Email Address: <input type='text' name='emaila' /> <br> UserName: <input type='text' name='usrn' /> Password: <input type='password' name='passw' /> <input type='submit' id='button' value='Submit' name='login' /> </form>
我为那些奇怪的命名变量预先表示歉意,我担心其他文件会打扰我在这里试图做的事情。
$con = mysqli_connect("localhost", "database_name", "password" "database_user"); //open connection if (mysqli_connect_errno()) { //if connection failed die("Connect failed: ", mysqli_connect_error()); exit(); } $lasty = mysqli_real_escape_string($con, $_POST['laz']); //added $con needs two parameter (connection, input) $namez = mysqli_real_escape_string($con, $_POST['namer']); $emailAddr = mysqli_real_escape_string($con, $_POST['emaila']); $UserName = mysqli_real_escape_string($con, $_POST['usrn']); $password = mysqli_real_escape_string($con, $_POST['passw']); $sqql = "INSERT INTO `table_name`(UserID, FirstName, LastName, Email, UserName, Password) VALUES (NULL, '$namez', '$lasty', '$emailAddr', '$userName', '$passwo')"; if (mysqli_query($con, $sqql)) { echo "Row inserted"; }else{ die("Error: ". mysqli_sqlstate($con)); } mysqli_close($con);