duancuo1234 2016-08-04 11:40
浏览 72


I am trying to insert data submitted in a form, into a MySQL Database, and I can't see the problem in my code(except for MySQL injection, that I will work to resolve after actually being able to insert any data). I have searched in Stack Overflow, and found someone who probably worked by the same manual, but I work in localhost, he's on GoDaddy. The solution given there doesn't work for me.

Here is my code for the HTML and the PHP code:

      $Fname = $_POST['FirstName'];
      $Lname = $_POST['LastName'];
      $Email = $_POST['Email'];
      $pw = $_POST['Password'];

  $sql= $con->query("INSERT INTO user (Fname,Lname,Email,Password) values('{$Fname}', '{$Lname}', '{$Email}', '{$pw}')");

  <!DOCTYPE html >
  <link href="css/Master.css" rel="stylesheet" type="text/css" />
  <link href="css/Menu.css" rel="stylesheet" type="text/css" />


  <div class="container">
    <div class="header">

    <div class="menu">
      <div id="NavBar">
       <a href="Login.php">Login</a>
       <a href="Register.php">Register</a>

    <div class="leftBody"></div>
    <div class="rightBody">
      <form  action="" method="post" name="RegisterForm" id="RegisterForm">
      <div class="FormElement">
      <input name="FirstName" id="FirstName" type="text" placeholder="First Name" class="TField">
       <div class="FormElement">
      <input name="LastName" id="LastName" type="text" placeholder="Last Name" class="TField">
       <div class="FormElement">
      <input name="Email" id="Email" type="email" placeholder="E-Mail" class="TField">
       <div class="FormElement">
      <input name="Password" id="Password" type="password" placeholder="Password" class="TField">
      <input name="Register" id="Register" type="button" value="Register" class="regButton">

    <div class="footer"></div>



And this is my connection.php file: That it does show that it connects.

if (!$con) {
    die("Could not connect: " . mysqli_error());
echo "Connected successfully";

And a picture of my database in phpMyAdmin: Database

I have tried also using this line like this for some reason, but to no avail.:

$sql= $con->query("INSERT INTO user
                   values ('Fname', 'Lname', 'Email', 'pw')");
  • 写回答

2条回答 默认 最新

  • dongshen4129 2016-08-04 11:50

    i didn't see submit button that actually submit the form. So if i am not wrong please try to use

    <input name="Register" id="Register" type="submit" value="Register" class="regButton">
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 NeRF的代码复现以及人工智能入门
  • ¥15 centos如何做一个可以让ikuai连接的openvpn
  • ¥15 Protege 中的Entities下面的界面删除了如何复原
  • ¥15 scrapy爬虫求帮
  • ¥15 imageEnView绘图问题
  • ¥15 关于#python#的问题:您好可以加您一下联系方式吗,在复现的时候确实有点问题难以解决
  • ¥15 联想电脑重装系统时无法发现硬盘
  • ¥15 MATLAB与UR10e实体机械臂建立通讯
  • ¥15 c++题需要快一点不用opencv
  • ¥15 关于#java#的问题:想要咨询Flowable流程引擎框架的问题