当我尝试更新到数据库中时,我收到错误。错误说:
您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本对应的手册,了解在第 6 行的"WHERE company_id='2"附近使用的正确语法
第 6 行与什么相关以及如何解决?
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Parse the form data and update company information to the system
if (isset($_POST['company_name'])) {
$pid = mysql_real_escape_string($_POST['thisID']);
$company_name = mysql_real_escape_string($_POST['company_name']);
$company_url = mysql_real_escape_string($_POST['company_url']);
$company_username = mysql_real_escape_string($_POST['company_username']);
$company_password = mysql_real_escape_string($_POST['company_password']);
// See if that company name is an identical match to another company in the system
$sql = mysql_query("UPDATE company SET
company_name='$company_name',
company_url='$company_url',
company_username='$company_username',
company_password='$company_password',
WHERE company_id='$pid'") or die(mysql_error());
header("location: company.php");
exit();
}
?>
<?php
// Gather these companies full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
$targetID = $_GET['pid'];
$sql = mysql_query("SELECT * FROM company WHERE company_id='$targetID' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$company_id = $row["company_id"];
$company_name = $row["company_name"];
$company_url = $row["company_url"];
$company_username = $row["company_username"];
$company_password = $row["company_password"];
}
} else {
echo "Sorry dude that doesn't exist.";
exit();
}
}
?>
在company_password='$company_password'
之后去掉逗号
WHERE
前面有多余的逗号,这是一个错误。因此,将其删除。
$sql = mysql_query("UPDATE company SET
company_name='$company_name',
company_url='$company_url',
company_username='$company_username',
company_password='$company_password' // REMOVE COMMA FROM HERE
WHERE company_id='$pid'") or die(mysql_error());
您在 where 子句之前放置了逗号 (,)。
company_password='$company_password'
**,**
WHERE company_id='$pid'"