Hello All,
I'm new to PHP, need some advice for my problem below.
Here is my problem after enter my fullname and search, it show all the fields from a table, but if I enter a invalid fullname(fullname that doesn't exist in fields) , the page goes blank no error has been specified.

example: fullname = James Lee(work fine)
fullname = Jamesss Leeee(page goes blank)

Thank In Advance.

<?php

session_start();

	$action=$_POST["submit"];
		
	if ($action=="Back")
	{
		header("Location:empmenu.php");
	
	}
	else
	{

$search = $_POST["search"];
//in this section user must search colleague info by using fullname.
if (@mysql_connect("localhost","root",""))
	{
		if (@mysql_select_db("ems"))
		{			
		
		$sql = "SELECT * FROM employee WHERE fullname = '$search'";
			$result = mysql_query($sql) or die('Error, query failed '. mysql_error());
			while($row=mysql_fetch_array($result))
			{
					$photo = $row[photo];
					$empid = $row[empid];
					$fullname = $row[fullname];
					$address = $row[address];
					$dob = $row[dob];
					$gender= $row[gender];
					$contactno = $row[contactno];
					$email = $row[email];
					
		}
				}
				 }
				 }
			?>

I think you need to specify your connection in the mysql_error() expression on line 23.
On line 17 e.g. :

$dbc = mysql_connect("localhost","root","");

and than on line 23 :

$result = mysql_query($sql) or die('Error, query failed '. mysql_error($dbc));

Try this

<?php

session_start();

$action = $_POST["submit"];

if ($action == "Back") {
    header("Location:empmenu.php");

} else {

    $server = mysql_connect("localhost", "root", "");
    $selectDB = mysql_select_db("ems");
    $search = $_POST["search"];
    //in this section user must search colleague info by using fullname.
    if ($server) {
        if ($selectDB) {

            $sql = "SELECT * FROM employee WHERE fullname = '$search'";
            $result = mysql_query($sql) or die(mysql_error());
            if (mysql_num_rows($result) > 0) {
                while ($row = mysql_fetch_array($result)) {
                    $photo = $row[photo];
                    $empid = $row[empid];
                    $fullname = $row[fullname];
                    $address = $row[address];
                    $dob = $row[dob];
                    $gender = $row[gender];
                    $contactno = $row[contactno];
                    $email = $row[email];

                }
            } else
                echo "No result found for <b>" . $search . "</b>";
        }
    }
}
?>

Hello again
Thanks for the reply Geertc and lili.edryana.

lili.edryana.: I have try to run the Php with yours, it does show the error "No result found for" but the information from the database does not appear in the table.
It is I miss something on opening and closing curly brace.
Thank In Advance

FORM

<form method="post" action="do_empseaemp.php">
  <tr>
  <td bgcolor="#FFCC00">Fullname<font color="red">*</font>: </td>
  <td>
 
  <input type="text" name="search" />
 </td>
</tr>



<tr>
  <td height="32" align="center">  </td>
  <td align=<"center">
 <input type="submit" value="Search" name="submit"></tr>
</table>
</form>
	
</table>
<?php

session_start();

$action = $_POST["submit"];

if ($action == "Back") 
{
    header("Location:empmenu.php");

} 
else 
{

    $server = mysql_connect("localhost", "root", "");
    $selectDB = mysql_select_db("ems");
    $search = $_POST["search"];
    //in this section user must search colleague info by using fullname.
    if ($server) 
	{
        if ($selectDB) 
		{

            $sql = "SELECT * FROM employee WHERE fullname = '$search'";
            $result = mysql_query($sql) or die(mysql_error());
            if (mysql_num_rows($result) > 0) 
			{
                while ($row = mysql_fetch_array($result)) 
				{
                    $photo = $row[photo];
                    $empid = $row[empid];
                    $fullname = $row[fullname];
                    $address = $row[address];
                    $dob = $row[dob];
                    $gender = $row[gender];
                    $contactno = $row[contactno];
                    $email = $row[email];

          
               }
            } else
                echo "No result found for <b>" . $search . "</b>";
        }
    }
}
?>


 <table width="57%" height="239%" align="center" border="0" cellpadding="4" cellspacing="4" bgcolor="#FFFF99">
<tr> 
            <td colspan="3"  bgcolor="#FFCC00" >Basic Colleague Information</td>
          </tr>
         
<tr><td bgcolor="#FFCC00">Photo : </td><td><img src= "<?php echo $photo; ?>" height="100" width="100"> </td></tr>

<tr><td bgcolor="#FFCC00">Emp ID : </td><td><?php echo $row['empid'];?></td></tr>

<tr><td bgcolor="#FFCC00">Fullname : </td><td><?php echo $row['fullname'];?></td></tr>

<tr><td bgcolor="#FFCC00">Address : </td><td><?php echo $row['address'];?></td></tr>

<tr><td bgcolor="#FFCC00">DOB : </td><td><?php echo $row['dob'];?></td></tr>

<tr><td bgcolor="#FFCC00">Gender : </td><td><?php echo $row['gender'];?></td></tr>

<tr><td bgcolor="#FFCC00">Contact No : </td><td><?php echo $row['contactno'];?></td></tr>

<tr><td bgcolor="#FFCC00">Email: </td><td><?php echo $row['email'];?></td></tr>




<tr>
<td height="32" align="center">
  </td>
  
  <td align=<"center">
 <input type="submit" value="Back" name="submit">


</tr>
</table>
	</form>
	
</table>

take a look at this line..

<tr><td bgcolor="#FFCC00">Emp ID : </td><td><?php echo $row['empid'];?></td></tr>

replace $row; with $empid

because you assign the array filed to the variable.

Hello,
Thank You lili.edryana, replace it with $empid really work!. I really appreciate your help. With your help, I learn something new today!, thank again :). And thank Geertc for the reply =D.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.