2015-06-24 53 views
0

我正在嘗試使用PHP表單更新數據庫數據的代碼。我的代碼似乎不工作,因爲我所得到的是「無法更新數據」。當我檢查數據庫中的表時沒有更新完成。誰能告訴我什麼是錯我的代碼PHP更新數據庫的數據

的index.php

<body> 

<form method="post" action="update.php"> 
<table width="400" border="0" cellspacing="1" cellpadding="2"> 
<tr> 
<td width="100">ID</td> 
<td><input name="emp_id" type="text" id="emp_id"></td> 
</tr> 

<tr> 
<td width="100">Date of Birth</td> 
<td><input name="birth" type="date" id="birth"></td> 
</tr> 

<tr> 
<td width="100">Educational Background</td> 
<td><input name="edu" type="text" id="edu"></td> 
</tr> 

<tr> 
<td width="100"> </td> 
<td> 
<input name="update" type="submit" id="update" value="Update"> 
</td> 
</tr> 

</table> 
</form> 

update.php

<?php 
     $conn = mysqli_connect("localhost", "root", "", "test"); 
     if(! $conn) 
     { 
     die('Could not connect: ' . mysql_error()); 
     } 

     $emp_id = $_POST['emp_id']; 
      $birth = $_POST['birth']; 
      $edu = $_POST['edu']; 

    $sql = "UPDATE vtiger_leadscf 
       SET birth = '$birth', 
       edu = '$edu' 
       WHERE emp_id = '$emp_id'" ; 

    $retval = mysql_query($sql, $conn); 
    if(! $retval) 
    { 
    die('Could not update data: ' . mysql_error()); 
    } 
    echo "Updated data successfully\n"; 
    mysql_close($conn); 

?> 
+1

您正在使用mysqli和mysql。 使用其中任何一個 –

回答

0

替換查詢

$sql = "UPDATE vtiger_leadscf 
       SET birth = '".$birth."', 
       edu = '".$edu."' 
       WHERE emp_id = ".$emp_id ;