我正在尝试使用php更新mySQL数据库,但我遇到了一些错误:
解析错误:语法错误,意外'}',期待第29行C:\ xampp \ htdocs \ SLR \更新S110 PC01.php中的文件结束
以下代码:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "slr";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$soft_id = $_POST['soft_id'];
$soft_name = $_POST['soft_name'];
$installed_date = $_POST['installed_date'];
$expiry_date = $_POST['expiry_date'];
$product_key = $_POST['product_key'];
$sql = "UPDATE s110_pc01 ". "SET soft_name = $soft_name ".
"WHERE soft_id = $soft_id" ;
$retval = mysql_query( $sql, $link );
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($link);
}else {
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border =" 0" cellspacing = "1"
cellpadding = "2">
<tr>
<td width = "100">Software ID</td>
<td><input name = "soft_id" type = "text"
id = "soft_id"></td>
</tr>
<tr>
<td width = "100">Software Name</td>
<td><input name = "soft_name" type = "text"
id = "soft_name"></td>
</tr>
答案 0 :(得分:0)
尝试下面
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "slr";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$soft_id = $_POST['soft_id'];
$soft_name = $_POST['soft_name'];
$installed_date = $_POST['installed_date'];
$expiry_date = $_POST['expiry_date'];
$product_key = $_POST['product_key'];
$sql = "UPDATE s110_pc01 ". "SET soft_name = $soft_name ".
"WHERE soft_id = $soft_id" ;
$retval = mysql_query( $sql, $link );
if($retval ) {
echo "Updated data successfully\n";
} else {
die('Could not update data: ' . mysql_error());
mysql_close($link);
}
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border =" 0" cellspacing = "1"
cellpadding = "2">
<tr>
<td width = "100">Software ID</td>
<td><input name = "soft_id" type = "text"
id = "soft_id"></td>
</tr>
<tr>
<td width = "100">Software Name</td>
<td><input name = "soft_name" type = "text"
id = "soft_name"></td>
</tr>