如果orderstatus
的字段为null,则我尝试设置默认值,然后返回给用户"正在进行中#34;如果不是null,则向用户提供字段内容。
我做了第二部分,但是如果字段为空则我无法获取代码的默认值:
<div id="par3" class="box">
<div class="container">
<center>
<div class="boxhead"><div id="heads">Forgot Password</div></div><br>
<div class="text">
<form action="" method="POST">
Order ID:
<input type="text" name="orderid" class="input" id="form-controls" placeholder="Your OrderID" AutoComplete="off">
<br /><br />
<input type="submit" name="submit" class="btn btn-warning" value="Recover">
<?php
if( isset($_POST['submit'])) {
$orderid=$_POST['orderid'];
$orderid = mysql_real_escape_string($orderid);
################################################
$checkname = "SELECT * FROM neworder WHERE ID='".$orderid."'";
if(mysql_num_rows(mysql_query($checkname)) < 1 )
{ $errors .= '<script>$.jGrowl("<b><u>Recover Failed</u></b><br>Username not found!", { theme: "error",speed: "fast",});</script>'; }
################################################
################################################
################################################
if(empty($orderid))
{ $errors .= '<script>$.jGrowl("<b><u>Recover Failed</u></b><br>All of fields are required.", { theme: "error",speed: "fast",});</script>'; }
################################################
################################################
if(!empty($errors))
{ echo "<div align='center'>".nl2br($errors)."</div>"; }
else {
$success=mysql_query("SELECT * FROM neworder WHERE ID='".$orderid."'");
$success1=SELECT IF(orderstatus IS NULL or orderstatus = '', 'empty', orderstatus ) as orderstatus
from neworder;
}
if($success || $success1){
echo "Password recovered successfully ! <br />";
while($row = mysql_fetch_array( $success )){
$orderstatus=$row['orderstatus'];
echo "Order Status: <font style='text-shadow: 0 0 15px rgb(153, 204, 0); color: rgb(153, 204, 0);'>".$orderstatus."</font> <br />";
}
}
}
?>
</form>
</div>
</div>
</center>
<div class="boxfooter"></div>
</div>
任何人都告诉我,我应该使用她有什么乐趣并且适合该代码,谢谢
答案 0 :(得分:0)
试试这个
SELECT IF(orderstatus IS NULL or orderstatus = '', 'empty', orderstatus ) as orderstatus
from neworder(your table name)
这将检查字段是空还是NULL
答案 1 :(得分:-1)
检查字段是空还是空
SELECT IF(Columnfield1 IS NULL or Columnfield1 = '', 'empty', Columnfield1) as field
from NameofYourTable