我试图更新数据库表中的条目,但我不断收到以下错误消息:
更新错误报告 ------请拨打UPDATEBUGREPORT.PHP --------- DEBUG PRINT 11:ShowForm:FALSE DEBUG PRINT 26:report_id set:4
警告:mysqli_errno()只需要在第43行的C:\ xampp \ htdocs \ Bugtracker \ UpdateBugReport.php中给出1个参数,0
警告:mysqli_error()预计在第43行的C:\ xampp \ htdocs \ Bugtracker \ UpdateBugReport.php中给出1个参数0 无法连接到数据库服务器。 错误代码 : 查看错误报告
我的代码是:
<!DOCTYPE html>
<head>
<title>Update a Bug Report</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Update Bug Report</h1>
<?php
echo "------CALL TO UPDATEBUGREPORT.PHP---------<br /> \n";
$ShowForm=FALSE;
echo "DEBUG PRINT 11: ShowForm: FALSE <br /> \n";
$fields = array('product', 'version', 'hardware', 'os', 'frequency', 'solutions');
$report=array();
foreach ($fields as $field)
$report[$field]="";
// if report_id field has been set from calling form
if (isset($_POST['report_id'])) {
$report_id=$_POST['report_id'];
}
else if (isset($_GET['report_id'])) {
$report_id=$_GET['report_id'];
}
if (isset($report_id)) {
echo "DEBUG PRINT 26 : report_id set : $report_id <br /> \n";
$DBConnection = mysqli_connect("...", "...", "...");
if (!$DBConnection === FALSE)
echo "<p>Unable to connection to the database server.</p>\n" .
"<p>error code " . mysqli_errno() . ": " . mysqli_error() . "</p> \n";
// db selection successful
else {
$DBName = "r00054908_bugreports";
$TableName = "bugtracker";
if (!mysqli_select_db($DDConnection,$DBName))
echo "<p>Unable to connect to the $DBName database!</p>";
else {
$SQLString="SELECT * FROM $TableName WHERE report_id='" .
stripslashes($report_id) . "'";
$QueryResult = mysqli_query($DBConnection,$SQLString);
if (!$QueryResult === FALSE)
echo "<p>There was an error retrieving the record.<br />\n" .
"The error was " .
htmlentities(mysqli_error($DBConnection)) .
".<br />\nThe query was '" .
htmlentities($SQLString) .
"'</p>\n";
else if (mysqli_num_rows($QueryResult)==0) {
echo "<p>" . stripslashes($report_id) . " is an invalid id</p>\n";
}
else {
$report=mysqli_fetch_assoc($QueryResult);
echo "DEBUG PRINT: Fetched record <br /> \n";
if (isset($_POST['submit'])) {
echo "DEBUG PRINT 60: Form submitted with UPDATE data. <br /> \n";
// validate form fields
foreach ($fields as $field) {
if ((!isset($_POST[$field])) || strlen(trim(($_POST[$field]))==0)) {
echo "<p>'$field' is a required field.</p>\n";
$ShowForm=TRUE;
echo "DEBUG PRINT: ShowForm: TRUE <br /> \n";
}
else {
$report[$field]=stripslashes(trim($_POST[$field]));
}
}
// update db with new data
if ($ShowForm===FALSE) {
echo "DEBUG PRINT : ShowForm: FALSE<br /> \n";
$connector="";
//build update sql string
$SQLString = "UPDATE $TableName SET ";
foreach ($field as $fields) {
$SQLString .= $connector . $field . "='" . $report[$field] . "'";
$connector=", ";
}
$SQLString .= "WHERE report_id = '" .$report_id. "'";
echo "DEBUG PRINT 87: UPDATE SQL: $SQLString <br /> \n";
$QueryResult = mysqli_query($DBConnection,$SQLString);
if ($QueryResult === FALSE)
echo "<p>There was an error saving the record. <br />\n" .
"The error was " .
htmlentities(mysqli_error($DBConnection)) .
".<br />\nThe query was '" .
htmlentities($SQLString) .
"'</p>\n";
else {
echo "<p>The bug report was saved.</p>\n";
}
}
else {
$ShowForm=TRUE;
echo "DEBUG PRINT 104 : ShowForm: TRUE <br />\n";
}
}
}
}
}
}
else {
echo "<p>You must select a report to update.</p>\n";
$ShowForm=FALSE;
echo "DEBUG PRINT 114: ShowForm: FALSE <br /> \n";
}
if ($ShowForm===TRUE) {
?>
<form action='UpdateBugReport.php' method='POST'>
<table>
<tr><td align='right'>Report ID</td><td align='left'> <?php echo $report['$report_id']; ?>
<input type='hidden' name='report_id' value='<?php echo $report['report_id']; ?>' />
</td></tr>
<tr><td align='right'>Product</td><td align='left'>
<input type='text' size='80' name='product' value='<?php echo $report['product']; ?>' />
</td></tr>
<tr><td align='right'>Version</td><td align='left'>
<input type='text' size='80' name='version' value='<?php echo $report['version']; ?>' />
</td></tr>
<tr><td align='right'>Type of Hardware</td><td align='left'>
<input type='text' size='80' name='hardware' value='<?php echo $report['hardware']; ?>' />
</td></tr>
<tr><td align='right'>Operating System</td><td align='left'>
<input type='text' size='80' name='os' value='<?php echo $report['os']; ?>' />
</td></tr>
<tr><td align='right'>Frequency of Occurrence</td><td align='left'>
<input type='text' size='80' name='frequency' value='<?php echo $report['frequency']; ?>' />
</td></tr>
<tr><td align='center' colspan='2'>Please either enter both the count and period, as in 20 times a month,
or a descriptive term, like 'often', 'rarely', or 'always'.</td></tr>
<tr><td align='right'>Proposed Solutions</td><td align='left'>
<textarea cols='80' rows='6' name='solutions'><?php echo $report['solutions']; ?></textarea>
</td></tr>
<tr><td align='center' colspan='2'>
<input type='reset' name='reset' value='Clear Form' />
<input type='submit' name='submit' value='Save Report' />
</td></tr>
</table>
<?php
}
?>
<a href="ViewBugReport.php">View Bug Reports</a>
</body>
</html>
谢谢。
答案 0 :(得分:0)
mysqli_errno和mysqli_error 不用于连接错误,因此替换
$DBConnection = mysqli_connect("157.190.186.37", "R00054908", "R00054908");
if (!$DBConnection === FALSE)
echo "<p>Unable to connection to the database server.</p>\n" .
"<p>error code " . mysqli_errno() . ": " . mysqli_error() . "</p> \n";
通过
$DBConnection = mysqli_connect("...", "...", "...");
if (mysqli_connect_error()) {
echo "<p>Unable to connect to the database server.</p>\n" .
"<p>error code " . mysqli_connect_errno() . ": " . mysqli_connect_error() . "</p> \n";
die;
}
然后再试一次。它不会解决数据库连接问题,但至少应该告诉你实际出错了什么....
请参阅:http://docs.php.net/mysqli.construct
编辑:
无论如何,if (!$DBConnection === FALSE)
行应该做什么?将$ DBConnection转换为布尔值而不是否定它然后测试&#34;为假&#34;?这没有任何意义,可能会测试你想要在那里测试的完全相反的东西。