我有一个基于产品保修信息的项目我创建了MySQL数据库并插入了数据,并且能够以规定的格式获取数据并且工作正常
现在的问题是,如果保修卡号存在,它显示产品信息没关系,但如果不存在,则显示空白格式页面,没有产品详细信息,这是问题。
如果数据不存在,我需要返回页面,或者像check check waranty card number
那样回复plz help
w c nuo。 :LP8200FA
提供报酬
主页上的代码
<form name="form" method="POST" action="cased.php">
Warranty Number <input type="text" name="search"> <br><br>
<input type="submit" value="submit">
</form>
cased.php页面上的代码
<?php
$connection = mysql_connect('localhost','aa_admin','aaaaaa') or die ("Couldn't connect to server.");
$db = mysql_select_db('sagemax_case', $connection) or die ("Couldn't select database.");
$warno=$_POST['search'];
$data = 'SELECT * FROM `cases` WHERE `warno` = "'.$warno.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);?>
{
Warranty Number :</td><td class="txtcssleft"><?php echo $data2['warno'] }?>
实际上他们是2页,一个是表单页面,另一个是保修信息页面,我需要在进入保修页面之前检查详细信息,如果详细信息仅在详细信息不可用时应该在同一页面中。请查看网站上的实际链接
我试过
$data = 'SELECT * FROM `cases` WHERE `warno` = "'.$warno.'"';
if(mysql_num_rows($query)>0){
header( "Location: cased.php" )
}else{
//We have no results and can't find the warranty, return a different page saying no warranty results exist
header( "Location: wc.php" )
但没有用请帮助
答案 0 :(得分:1)
您需要添加一个If语句来检查是否得到了结果。
if(mysql_num_rows($query)>0){
//We have results, return formatted page here
}else{
//We have no results and can't find the warranty, return a different page saying no warranty results exist
}
答案 1 :(得分:0)
在使用以下内容向页面呈现任何内容之前检查是否有行。如果查询未返回任何行,则根据需要进行回显或重定向。
@Aidan打败了我,他的解决方案也会奏效。我只是省略了&gt; 0。session_start(); // You need this to use session variables. Add it to the destination page also.
if(mysql_num_rows($query))
{
// Updated the following to account for OP's comment.
$_SESSION['data2'] = $data2; // This supposes that you session_start();
// Do what you're currently doing if a row is returned.
}
else
{
// There are no rows returned.
echo "What, dude, no rows! Check your warranty card!";
}
如果您想将结果传递到新页面,