dsf12123 2016-03-18 14:40
浏览 35
已采纳

MySQLi输入数据到数据库[重复]

How can I get my form to input the fields to my database using MySQLi (mysqli procedural) I currently have this but it goes though when I submit with no errors but nothing goes into the database.

 <?php

    if(isset($_POST["submit"])){
    $Fname = $_POST['firstname'];
    $Lname = $_POST['lastname'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $bday = $_POST['bday'];

$servername = "<--enter servername -->";
$username = "<--enter username -->";
$password = "<--enter password -->";
$database = "<--enter datbase name -->";

  // Create connection
  $conn = mysqli_connect($servername, $username, $password, $database);

    $sql = "INSERT INTO Questions_users (Fname, Lname, email, gender, bday)
    VALUES ('$Fname','$Lname','$email','$gender','$bday')";

    if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
    } else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    mysqli_close($conn);
    }
    ?>

And the form is

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" name="firstname"></td>
<input type="text" name="lastname"></td>
<input type="email" name="email"></td>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female</td>
<input type="date" name="bday"></td>
<input type="submit" value="Submit"></form>
</div>
  • 写回答

1条回答 默认 最新

  • doujing6436 2016-03-18 14:43
    关注

    You'll need to set the name attribute for this:

    <input type="submit" name="submit" value="Submit">
    

    Your PHP code was not executed as you set the condition if(isset($_POST["submit"])){ and the submit element was not found.

    Also, you've missed out the closing bracket:

    $sql = "INSERT INTO Questions_users (Fname, Lname, email, gender, bday)
    VALUES ('[$Fname]','[$Lname]','[$email','[$gender]','[$bday]')";
    

    '[$email' should be '[$email]'.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?