2014-02-26 75 views
-6

我想用一個簡單的網頁來更新我的mysql表格的一個單元格。我不知道爲什麼它不會將數據發送到我的表格。我有兩個網頁。 form.php和process.php。以下是各自的代碼。這應該是現在工作。我不明白。爲什麼我的網頁不能將數據插入到mysql表中?

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"]; 
?> 
+0

哇,這讓比我更少的感覺,當我酗酒,經過一夜回家。 -1猜測代碼通常不起作用 – PeeHaa

+0

錯誤:'[WHERE ID = 1]' – 2014-02-26 20:08:09

+0

錯誤:'「」UPDATE' –

回答

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 :) ? " ; 
    } 
+0

$ inputtest看起來像一個字符串 – 2014-02-26 20:10:37

+0

-1爲sql注入 – PeeHaa

+0

@Dagon它沒有問題,單引號或沒有 –

相關問題