【发布时间】:2014-11-14 01:44:10
【问题描述】:
我有一个网站,其中用户必须已经存在于数据库中才能继续到下一页。我进行了一个查询,将他们的名字、姓氏和电子邮件地址与存储在数据库中的人进行比较,如果它们匹配,我可以让它打印结果,但我不能让它返回一个真实的或我想要的东西可以使用以执行操作。我需要向用户发送一封电子邮件,然后将他们重定向到另一个页面,你也可以帮忙吗?
这是我的代码
<?php
include("dbconnect.php");
$firstname=$_POST["firstname"];
$lastname=$_POST["lastname"];
$email=$_POST["email"];
$connect = $conn;
if (!$connect) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Prepare the statement
$stid = oci_parse($connect, "SELECT * FROM USERS WHERE firstname = '$firstname' AND lastname = '$lastname' AND email = '$email'");
if (!$stid) {
$e = oci_error($connect);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
$e = oci_error($stid);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Fetch the results of the query
print "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
print "<tr>\n";
foreach ($row as $item) {
print " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
oci_free_statement($stid);
oci_close($connect);
?>
如果你能帮我运行一个动作,如果为真(发送电子邮件和重定向),如果用户在数据库中不存在,则显示错误。谢谢 - 我对 PHP 很陌生
【问题讨论】:
-
那么,如果你的数据库查询结果不是 null 或者 0 你可以进入下一页吗?
-
使用php.net/manual/en/function.oci-num-rows.php 检查行数。如果计数为 1(或更大),请运行您的操作。如果为 0,则显示错误消息。
-
我不明白你的问题。如果您从数据库中获取信息,为什么不将它们与给定的用户输入进行比较?如果它们匹配,您可以将变量设置为 true。只需将您从查询中获得的数据推送到变量中。
-
对不起,我编程真的很烂,甚至不知道怎么做:l
-
我尝试在 $stid 上运行 if 语句,但它不起作用,我在哪里比较?