为什么我的网页没有将数据插入mysql表?

时间:2014-02-26 20:06:05

标签: php html mysql sql

我试图拥有一个带有表单的简单网页来更新我的mysql表的一个单元格。我不确定为什么它没有将数据发送到我的桌子。我有两个网页。 form.php和process.php。下面分别是每个代码。这应该是现在正在运作。我不明白。

form.php的

<!DOCTYPE HTML PUBLIC
<html>
<head>
      <title></title>
 </head>

<body>

<!-- form to get key detail of record in database -->
<form method="POST" action="process.php"> 
<input type="text" name="inputtest" />
<input type="submit" name"submitButton" value="Submit!" /> 
</form> 

</body>
</html>

process.php

<?php
$con=mysqli_connect("localhost","root","Michfball#16","allstate");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,""UPDATE * TO producers
    SET TEST={$inputtest}
    [WHERE ID=1]");
?>
<?php
   $inputtest = $_POST["inputtest"];
?>

1 个答案:

答案 0 :(得分:2)

您应该在更新之前定义并转义变量。 试试这个

 $inputtest = mysqli_real_escape_string($_POST["inputtest"]);
 $result = mysqli_query($con,"UPDATE  producers
                              SET TEST= '$inputtest'
                              WHERE ID =1 ");

你的代码应该是那样的

 if(isset($_POST["inputtest"])){
 $inputtest = mysqli_real_escape_string($_POST["inputtest"]);
 $result = mysqli_query($con,"UPDATE  producers
                              SET TEST= '$inputtest'
                              WHERE ID =1 ");
   } 
 else {
  echo "what are you doing here :) ? " ;
    }