tags:

views:

84

answers:

4

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

+1  A: 

Use

if (!isset($ss)) {
    echo "please write your search words";
}

instead of

if (empty($ss)) {
    echo "please write your search words";
}
yankitwizzy
Sorry I meant to writeif (!isset($ss)) { echo "please write your search words"; }
yankitwizzy
yes i tried your code but The message that appears to me You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
migo
this is the link for my full html php sql codeplzzz helphttp://www.mediafire.com/?2d4yzdjiym0
migo
+1  A: 

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.

Re0sless
The message that appears to meYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
migo
this may be due to you using $ss in the line $sql2=("SELECT * FROM student WHERE snum = $ss"); that comes before you check, if you replace the line $ss = $_POST["ss"]; with my second code sample does it sort it out?
Re0sless
A: 

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.

Jan Kuča
i tried this and not work too
migo
A: 

$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 ...

yankitwizzy