我目前正在构建一个获取唯一值并将其用作登录名(即参考号)的系统。然后参考号搜索数据库并将所有相应的数据输出到另一个页面,我正在努力解决这个问题,我的代码是:
索引.PHP
<input name="search_box" type="text" class="auto-style1" id="search_box" style="width: 240px; height: 30px" maxlength="12">
<input type="submit" name="search" value="Enter" class="auto-style1" style="width: 63px; height: 30px"></td>
<?php $reasons = array("search_box" => "Please Enter Valid Reference Number", "" => "Error"); if ($_GET["loginFailed"]) echo $reasons[$_GET["reason"]]; ?>
</form>
检查.php
<?php
include "conn.php";
mysql_connect("localhost","root") or die(header("location:index.php?loginFailed=true&reason=search_box"));
mysql_select_db("DB1") or die(header("location:index.php?loginFailed=true&reason=search_box"));
$reference1 = $_POST['search_box'];
$sql = "SELECT * FROM test_table1 WHERE No =$R1";
$result = mysql_query($sql) or die(mysql_error());
if ($result)
$count = mysql_num_rows($result);
else
$count = 0;
if($count == 1)
{
session_register('search_box');
header("location:result.php");
}
else
{
echo (header("location:index.php?loginFailed=true&reason=search_box"));
}
?>
输出.php
<?php
include "conn.php";
$sq2 = "SELECT * FROM test_table1";
if (isset($_POST['search']))
{
$search_term = mysql_real_escape_string($_POST['search_box']);
$sq2 .= "WHERE No = '{$search_term}'";
}
$query= mysql_query($sq2, $con);
while($row = mysql_fetch_array($query)) { ?>
<font size="4" face="Calibri"><b> Ref Number: </b> </font><?php echo $row['No']; ?></td>
<p>
<font size="4" face="Calibri"><b> Location: </b></font><?php echo $row['Country']; ?></td>
<p>
<?php
mysql_close($con);
?>
你们能给予的任何帮助将不胜感激,谢谢。
QWERTY。