4 Replies - 2088 Views - Last Post: 03 May 2009 - 10:54 PM Rate Topic: -----

#1 alfalisyada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 25-February 09

if else not working for display message box

Posted 02 May 2009 - 10:25 PM

hello...i want to make search function when insert student matric and it will dislpay the details..but when student matric is not found it will display empty page and appear message box that tell the user record not found..i dont know where is the wrong in code because message box doesnt appear...the code is :

//php code
<?php 
	include ('dbconnect.php');
		if (isset($_POST['matric']))
		{
	$matric = $_POST['matric'];
	$query = "SELECT matric,name,programme,year,intake,sem,sponsor,icno,dob,religion,others,race,gender,status,address,zipcode,city,state,telno,email,fathername,telfather,mothername,telmother,guardianname,telguardian,relationship FROM student WHERE matric='$matric'";
		
		$result = mysql_query($query) or die(mysql_error());
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		}
		
		else
		{
		
		echo "<script type='text/javascript'>\n";
		echo "alert('Student Record Was Not Found. Please try again.');\n";
		echo "history.go(-1);\n";
		echo "</script>";
			}	
			?>



//table that will display student details

<table width="649" height="205" border="0" align="center" cellpadding="0" cellspacing="0" >
	<tr bgcolor="#FFFFFF">
			<td height="24" colspan="4" bgcolor="#FFFFFF" ><div align="center" class="style21"> <img src="images/holder.gif" width="35" height="32" /> .:: Student's Details ::. </div></td>
		</tr>
		  <tr>
			<td height="19" bgcolor="#FFFF99" >&nbsp;</td>
			<td colspan="3" bgcolor="#FFFF99" >&nbsp;</td>
		  </tr>
		  <tr>
			<td width="17" height="24" bgcolor="#FFFF99" >&nbsp;</td>
			<td width="110" bgcolor="#FFFF99" ><span class="style8">Matric</span></td>
			<td width="20" bgcolor="#FFFF99" ><div align="center" class="style8">:</div></td>
			<td width="502" bgcolor="#FFFF99"><input name= "matric" type="text" disabled="disabled" id="matric" value="<?php echo $row['matric'] ?>" size="50" />			</td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Name</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name= "name" type="text" disabled="disabled" id="name" value="<?php echo $row['name'] ?>" size="50"  /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Programme</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="programme" type="text" disabled="disabled" id="programme" value="<?php echo $row['programme'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Intake</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="intake" type="text" disabled="disabled" id="intake" value="<?php echo $row['intake'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Sem</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="sem" type="text" disabled="disabled" id="sem" value="<?php echo $row['sem'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Sponsor</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="sponsor" type="text" disabled="disabled" id="sponsor" value="<?php echo $row['sponsor'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">ICNo</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name= "icno" type="text" disabled="disabled" id="icno" value="<?php echo $row['icno'] ?>" size="50"  /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">D.O.B</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="dob" type="text" disabled="disabled" id="dob" value="<?php echo $row['dob'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Religion</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="religion" type="text" disabled="disabled" id="religion" value="<?php echo $row['religion'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Other Religion </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="religion" type="text" disabled="disabled" id="religion" value="<?php echo $row['others'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Race</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="race" type="text" disabled="disabled" id="race" value="<?php echo $row['race'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Gender</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="gender" type="text" disabled="disabled" id="gender" value="<?php echo $row['gender'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Status</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="status" type="text" disabled="disabled" id="status" value="<?php echo $row['status'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Address</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><textarea name="address" cols="38" disabled="disabled" id="address"><?php echo $row['address'] ?></textarea></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Zipcode</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="zipcode" type="text" disabled="disabled" id="zipcode" value="<?php echo $row['zipcode'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">City</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="city" type="text" disabled="disabled" id="city" value="<?php echo $row['city'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">State</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="state" type="text" disabled="disabled" id="state" value="<?php echo $row['state'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Telephone No </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="telno" type="text" disabled="disabled" id="telno" value="<?php echo $row['telno'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Email</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="email" type="text" disabled="disabled" id="email" value="<?php echo $row['email'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Father's Name </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="fathername" type="text" disabled="disabled" id="fathername" value="<?php echo $row['fathername'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Father's Tel </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="telfather" type="text" disabled="disabled" id="telfather" value="<?php echo $row['telfather'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Mother Name </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="mothername" type="text" disabled="disabled" id="mothername" value="<?php echo $row['mothername'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Mother's Tel </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="telmother" type="text" disabled="disabled" id="telmother" value="<?php echo $row['telmother'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Guardian's Name </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="guardianname" type="text" disabled="disabled" id="guardianname" value="<?php echo $row['guardianname'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Guardian's Tel </span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="telguardian" type="text" disabled="disabled" id="telguardian" value="<?php echo $row['telguardian'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style8">Relationship</span></td>
			<td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
			<td bgcolor="#FFFF99"><input name="relationship" type="text" disabled="disabled" id="relationship" value="<?php echo $row['relationship'] ?>" size="50" /></td>
		  </tr>
		  <tr>
			<td height="24" bgcolor="#FFFF99">&nbsp;</td>
			<td bgcolor="#FFFF99"><span class="style20"></span></td>
			<td bgcolor="#FFFF99"><span class="style20"></span></td>
			<td bgcolor="#FFFF99">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="4" align="right" bgcolor="#FFFF99"><table align="center">
				<tr>
				  <td><form action="edit.php" method="post" name="edit" id="edit">
					  <input name="matric" type="hidden" id="matric" value="<?php echo $row['matric'] ?>" />
					  <input type="submit" name="edit" value="Edit" />
				  </form></td>
				  <td><form action="delete.php" method="post" name="delete" id="delete">
					  <input name="matric" type="hidden" id="matric" value="<?php echo $row['matric'] ?>" />
					  <input type="submit" name="btnDel" value="Delete" />
				  </form></td>
				</tr>
			</table></td>
		  </tr>
	  </table>



Is This A Good Question/Topic? 0
  • +

Replies To: if else not working for display message box

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: if else not working for display message box

Posted 02 May 2009 - 10:54 PM

ok simply use this code

<?php

if(mysql_num_rows($Queryq)>0)
{
//show this table
}
else
{
//show this table
}
?>


Was This Post Helpful? 0
  • +
  • -

#3 alfalisyada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 25-February 09

Re: if else not working for display message box

Posted 03 May 2009 - 02:24 AM

hi...thanks for the reply...

i try already the code..but i still can't get what i want...i change the code like this
<?php 
	include ('dbconnect.php');
		if(mysql_num_rows($query)>0)
		{
	$matric = $_POST['matric'];
	$query = "SELECT matric,name,programme,year,intake,sem,sponsor,icno,dob,religion,others,race,gender,status,address,zipcode,city,state,telno,email,fathername,telfather,mothername,telmother,guardianname,telguardian,relationship FROM student WHERE matric='$matric'";
		
		$result = mysql_query($query) or die(mysql_error());
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		}
		
		else
		{



echo "<script type='text/javascript'>\n";
echo "alert('Student Record Was Not Found. Please try again.');\n";
echo "history.go(-1);\n";
echo "</script>";
}
?>
Was This Post Helpful? 0
  • +
  • -

#4 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: if else not working for display message box

Posted 03 May 2009 - 03:22 AM

I guess that noorahmad meant you to use his code like this:

<?php 
	include ('dbconnect.php');
	$matric = $_POST['matric'];
	$result = mysql_query("SELECT * FROM student WHERE matric='$matric'") or die(mysql_error());
	if(mysql_num_rows($result)>0)
	{
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
	}
	else
	{
		echo "<script type='text/javascript'>\n";
		echo "alert('Student Record Was Not Found. Please try again.');\n";
		echo "history.go(-1);\n";
		echo "</script>";
	}	
?>



[quote name='alfalisyada' date='3 May, 2009 - 01:24 AM' post='628360']
hi...thanks for the reply...

i try already the code..but i still can't get what i want...
Was This Post Helpful? 0
  • +
  • -

#5 alfalisyada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 25-February 09

Re: if else not working for display message box

Posted 03 May 2009 - 10:54 PM

hi wimpy...its success
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1