I'm a beginner and also a diploma student... I'm trying to update my MySQL database and I'm having error... Please help me... This is the error:
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:
This is my code:
<?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>
According to the documentation , the procedural version of mysqli_error()
requires you to pass the database handle as an argument. The correct call should be
if(! $result )
{
die('Could not Update data: ' . mysqli_error($link));
}
Also, in your UPDATE
statement, you need to specify the table being updated .
$sql = "UPDATE <table_name> 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]'";
you did mention table name and you are storing the $_POST values in separate variable use that in query
$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"
}
您错过了更新查询中的表名
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.