douduanque5850 2015-08-11 08:59
浏览 25

尝试使用注册表单中的PHP / Html将数据输入到SQL表中

I've tried so many different things and did many searches with no solution. I am trying to use an html form to submit data to a sql table.

Here is the code for my register.php file.

$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']);

$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;


My HTML file is:

<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' />


I apologize in advance for the weirdly named variables, I was afraid that the other files would interrupt what I was trying to do here.

  • 写回答

2条回答 默认 最新

  • doule0941 2015-08-11 09:02
    $con = mysqli_connect("localhost", "database_name", "password" "database_user"); //open connection
    if (mysqli_connect_errno()) { //if connection failed
        die("Connect failed: ", mysqli_connect_error());
    $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";
        die("Error: ". mysqli_sqlstate($con));
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 PdfiumViewer pdf转图片
  • ¥15 利用Java连接API接口总是出问题
  • ¥15 请教一个关于镜头标定,棋盘格格子大小的问题(畸变测试)
  • ¥15 el-table输入多维数组怎么实现
  • ¥15 安装GroudingDINO RuntimeError: Error compiling objects for extension
  • ¥15 关于推送项目到github的问题
  • ¥15 急!C++指针编写相关的问题
  • ¥15 kerberos身份认证配置问题
  • ¥30 用python写一个多签情况下波场的代理资源和回收资源
  • ¥15 怎么在matlab中输出显示泵的流量-扬程和管路损失与流量均在一个表格里