|
<?php
// modify.php
require "global.php";
include "jm.php";
$rowid=$_GET['rowid'];
$selectStmt = "select * from pa_address_book where rowid=$rowid";
// $selectStmt = "select * from pa_address_book where rowid={$_GET['rowid']}" ;
// connect to the database
if (!($link = mysql_pconnect("localhost", "root", "test")))
{
DisplayErrMsg(sprintf("error connecting to host %s, by user %s", $hostname, $username));
exit();
}
// select the database
if (!mysql_select_db("article20", $link))
{
DisplayErrMsg(sprintf("Error in selecting %s database", $databaseName));
DisplayErrMsg(sprintf("error: %d %s", mysql_errno($link), mysql_error($link)));
exit();
}
//execute the statement
if (!($result = mysql_query($selectStmt, $link)))
{
DisplayErrMsg(sprintf("Error in executing %s stmt", $selectStmt));
DisplayErrMsg(sprintf("error: %d %s", mysql_errno($link), mysql_error($link)));
exit();
}
GenerateHTMLHeader("Please modify fields");
if (!($row = mysql_fetch_object ($result)))
{
DisplayErrMsg("Internal error: the entry does not exist");
exit();
}
$resultEntry['user'] = $row->pa_user;
$resultEntry['ip'] = $row->pa_user_ip;
$resultEntry['company'] = $row->pa_user_company;
$resultEntry['department'] = $row->pa_user_department;
$resultEntry['job'] = $row->pa_user_job;
GenerateHTMLForm($resultEntry, "update.php?rowid=$rowid", "modify");
mysql_free_result($result);
--------------------------------------------------------------------------------
源码:--------------------------------------------------------------------------------
<?php
// main.php
require "global.php";
include "jm.php";
// Check if at least one search criteria is entered
if (!$pa_user && !$pa_user_ip && !$pa_user_company && !$pa_user_department && !$pa_user_job)
{
DisplayErrMsg("Error: At least one search criteria should be present\n");
exit();
}
//Generate the sql command for doing a select from the Database
$searchStmt = "select * from pa_address_book where " ;
if ($pa_user)
$searchStmt .="pa_user like '%$pa_user%' and ";
if ($pa_user_ip)
$searchStmt .="pa_user_ip like '%$pa_user_ip%' and ";
if ($pa_user_company)
$searchStmt .="pa_user_company like '%$pa_user_company%' and ";
if ($pa_user_department)
$searchStmt .="pa_user_department like '%$pa_user_department%' and ";
if ($pa_user_job)
$searchStmt .="pa_user_job like '%$pa_user_job%' and ";
$stmt = substr($searchStmt, 0, strlen($searchStmt)-4);
// connect to the database
if (!($link=mysql_pconnect ("localhost", "root", "test")))
{
DisplayErrMsg(sprintf("error connectint to host %s, by user %s", $hostName, $userName));
exit();
}
//select the database
if (!mysql_select_db("article20", $link))
{
DisplayErrMsg(sprintf("Error in selecting %s database", $databaseName));
DispalyErrMsg(sprintf("errord %s", mysql_errno($link), mysql_error($link)));
exit();
}
echo "$stmt";
// execute the statement
if (!($result = mysql_query($stmt, $link)))
{
DisplayErrMsg(sprintf("Error in executing %s stmt", $stmt));
DisplayErrMsg(sprintf("error: %d %s", mysql_errno($link), mysql_error($link)));
exit();
}
// display the result of the search
printf("<table border with=\"100%%\" bgcolor=\"#dcdcdc\" nosave>\n");
printf("<tr>
<td><b>pa_user</b></td>
<td><b>pa_user_ip</b></td>
<td><b>pa_user_company</b></td>
<td><b>pa_user_department</b></td>
<td><b>pa_user_job</b></td>
<td><b>modify/delete</b></td>
</tr>\n");
while (($row = mysql_fetch_object($result)))
{
printf( "<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=\"modify.php?rowid=%s\"><i>Modify</i></a>/
<a href=\"delete.php?rowid=%s\"><i>delete</i></a></td>
</tr>\n",
$row->pa_user,$row->pa_user_ip,$row->pa_user_company,$row->pa_user_department,$row->pa_user_job,$row->rowid,$row->rowid);
}
printf("</table>\n");
mysql_free_result($result);
echo "$rowid";
?>
错误是这个
Error in executing select * from pa_address_book where rowid= stmt
error: 1064 You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 |
|