mysqli_select_db($con, "wishlist");
$user = mysqli_real_escape_string($con, htmlentities($_GET["user"]));
$wisher = mysqli_query($con, "SELECT id FROM wishers WHERE name='" . $user . "'");
if (mysqli_num_rows($wisher) < 1) {
exit("The person " . htmlentities($_GET["user"]) . " is not found. Please check the spelling and try again");
} $row = mysqli_fetch_row($wisher); $wisherID = $row[0]; mysqli_free_result($wisher);
对于 Oracle 数据库:(请注意,oci8 没有等效的 mysqli_num_rows)
$query = "SELECT id FROM wishers WHERE NAME = :user_bv";
$stid = oci_parse($con, $query);
$user = $_GET['user'];
oci_bind_by_name($stid, ':user_bv', $user);
oci_execute($stid);
//Because user is a unique value I only expect one row
$row = oci_fetch_array($stid, OCI_ASSOC);
if (!$row) {
exit("The person " . $user . " is not found. Please check the spelling and try again" );
}
$wisherID = $row['ID'];
oci_free_statement($stid);
此 PHP 块现已完成。如果使用的是 MySQL 数据库,则会看到 wishlist.php 文件现在如下所示:
Wish List of <?php echo htmlentities($_GET["user"]) . "<br/>"; ?>
<?php
$con = mysqli_connect("localhost", "phpuser", "phpuserpw");
if (!$con) {
exit('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
//set the default client character set
mysqli_set_charset($con, 'utf-8');
mysqli_select_db($con, "wishlist");
$user = mysqli_real_escape_string($con, htmlentities($_GET["user"]));
$wisher = mysqli_query($con, "SELECT id FROM wishers WHERE name='" . $user . "'");
if (mysqli_num_rows($wisher) < 1) {
exit("The person " . htmlentities($_GET["user"]) . " is not found. Please check the spelling and try again");
}
$row = mysqli_fetch_row($wisher);
$wisherID = $row[0];
mysqli_free_result($wisher);
?>
如果使用的是 Oracle 数据库,则会看到 wishlist.php 文件现在如下所示:
Wish List of <?php echo htmlentities($_GET["user"]) . "<br/>"; ?>
<?php
$con = oci_connect("phpuser", "phpuserpw", "localhost/XE", "AL32UTF8");
if (!$con) {
$m = oci_error();
exit('Connect Error ' . $m['message'];
exit;
}
$query = "SELECT id FROM wishers WHERE name = :user_bv";
$stid = oci_parse($con, $query);
$user = htmlentities($_GET["user"]);
oci_bind_by_name($stid, ':user_bv', $user);
oci_execute($stid);
//Because user is a unique value I only expect one row
$row = oci_fetch_array($stid, OCI_ASSOC);
if (!$row) {
exit("The person " . $user . " is not found. Please check the spelling and try again" );
}
$wisherID = $row["ID"];
oci_free_statement($stid);
?>
如果测试应用程序并输入无效的用户,则会显示以下消息。
显示愿望表
在本部分中,将添加代码以显示与许愿者关联的 HTML 愿望表。许愿者是由在上一节的代码中检索的 ID 标识的。
在 PHP 块下面,键入或粘贴以下 HTML 代码块。该代码打开一个表,指定其边框颜色(黑色),然后使用 "Item" 和 "Due Date" 列“绘制”表标题。