I've noticed that the first condition does not work
if (empty($ss)) {
echo "please write your search words";
}
but the second does
else if ($num < 1) {
echo "not found any like ";
Full code:
<?php
require_once "conf.php";
$ss= $_POST["ss"];
$sql2=("SELECT * FROM student WHERE snum = $ss");
$rs2 = mysql_query($sql2) or die(mysql_error());
$num = mysql_num_rows($rs2);
if (empty($ss)) {
echo "please write your search words";
}
else if ($num < 1 ) {
echo "not found any like ";
}else {
$sql=("SELECT * FROM student WHERE snum = $ss ");
$rs = mysql_query($sql) or die(mysql_error());
while($data=mysql_fetch_array($rs)) {
?>
<div id="name">
<table align="center" border="3" bgcolor="#FF6666">
<tr>
<td><? echo $data ["sname"]." "."نتيجة الطالب"; ?></td>
</tr>
</table>
</div>
<div id="ahmed">
<table width="50%" height="50" align="center" border="2px" bgcolor="#BCD5F8">
<tr>
<td width="18%"><strong>جيولوجي</strong></td>
<td width="13%"><strong>تاريخ</strong></td>
<td width="13%"><strong>رياضة</strong></td>
<td width="14%"><strong>عربي</strong></td>
<td width="12%"><strong>علوم</strong></td>
<td width="30%"><strong>المادة</strong></td>
</tr>
<tr>
<td>100</td>
<td>100</td>
<td>100</td>
<td>100</td>
<td>100</td>
<td><strong>الدرجة النهائية</strong></td>
</tr>
<td><? echo $data['geo']; ?></td>
<td><? echo $data['snum']; ?></td>
<td><? echo $data['math']; ?></td>
<td><? echo $data['arab']; ?></td>
<td><? echo $data['history']; ?></td>
<td><strong>درجات الطالب</strong></td>
</tr>
<tr>
<td colspan="5" align="center" valign="middle">
<? $sum= $data['geo'] + $data['snum'] +
$data开发者_开发知识库['math'] + $data['arab'] +
$data['history'];
echo $sum ;
?>
</td>
<td><strong>مجموع الدرجات</strong></td>
</tr>
<tr>
<td colspan="5" align="center">
<?
$all=500 ;
$sum= $data['geo'] + $data['snum'] +
$data['math'] + $data['arab'] +
$data['history'];
$av=$sum/$all*100 ;
echo $av."%" ;
?>
</td>
<td><strong>
النسبة المئوية
</strong></td>
</tr>
</table>
</tr>
</div>
<?
}
};
The full code link is:
http://www.mediafire.com/?2d4yzdjiym0
Are you sure that $ss isset? i.e. there is a POST variable with the name ss. you could test it with.
if (empty($ss) || !isset($ss)) {
echo "please write your search words";
}
or test for it when you read in the post var
if ((!isset($_POST["ss"]) || (!is_numeric($_POST["ss"])))
{
$ss = 0;//empty considers 0 as been empty
}
else
{
$ss = $_POST["ss"];
}
ss looks to be a number too, so checking if it is numeric using is_numeric will help stop SQL errors, if for some reason it is not.
Use
if (!isset($ss)) {
echo "please write your search words";
}
instead of
if (empty($ss)) {
echo "please write your search words";
}
Try changing the condition to
if(empty($_POST['ss'])){ ... }
and continue using $_POST['ss'] instead of $ss.
BTW Always use error_reporting(E_ALL) when developing.
$sql=("SELECT * FROM student WHERE snum = $ss ");
Remove the brackets in the variables ($sql1 and $sql2) that have your query
It should be
$sql="SELECT * FROM student WHERE snum = $ss ";
I think that's why its telling you that you have an error near ...
精彩评论