我正在尝试更新我的mysql数据库

时间:2016-04-11 05:29:14

标签: php mysql

我是初学者,也是文凭学生...我正在尝试更新我的MySQL数据库而且我有错误...请帮帮我...... 这是错误:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\SLR\Update S110 PC01.php on line 24
Could not Update data:

这是我的代码:

<?php

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="slr"; // Database name 
$tbl_name="s110_pc01"; // Table name 

// Connect to server and select database.
$link =  mysqli_connect("$host", "$username", "$password")or die("cannot connect"); 
mysqli_select_db($link, $db_name)or die("cannot select DB");

// Get values from form 
$soft_name=$_POST['soft_name'];
$installed_date=$_POST['installed_date'];
$expiry_date=$_POST['expiry_date'];
$product_key=$_POST['product_key'];


$sql = "UPDATE  SET soft_name='$_POST[soft_name]', installed_date='$_POST[installed_date]', expiry_date='$_POST[expiry_date]', product_key='$_POST[product_key]' WHERE soft_id='$_POST[soft_id]'";
$result=mysqli_query($link,$sql);
if(! $result )
{
  die('Could not Update data: ' . mysqli_error());
}
echo "Successfully updated\n";
mysqli_close($con);
?>
<input type="button"value="Finish"onclick="window.location.href='Update S110 PC01 Data.php'">
</form>
</table>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您确实提到了表名,并且您将$ _POST值存储在查询

中的单独变量中
 $sql = "UPDATE Table_name SET soft_name='$soft_name', installed_date='$installed_date', expiry_date='$expiry_date', product_key='$product_key' WHERE soft_id='$_POST[soft_id]'";
$result=mysqli_query($link,$sql);
if($result===TRUE)
{
echo "updated"
}
else
{
echo "not update"
}