Need help with mysql query using php

mysql

#1

I'm trying to retrieve data from the database using "Admission no" which is working fine, but my problem is, it shows blank table even when wrong admission no is entered, so instead i want to show "Admission no not found" error.
I'm not able to sort it out, can someone help me with this?

<?php
include_once("bg.php");
ob_start();
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
	//Connect to dataBase
	$mysqli=mysqli_connect("localhost","dbuser","dbpass","dbname");
		$search = $mysqli->real_escape_string($_POST['search']);
	//query the Database
	$resultSet = $mysqli->query("SELECT * FROM stud_adm WHERE adm_no = '$search'");
	$row= mysqli_fetch_array($resultSet);
}
?>
<html>
<head>
<title></title>
</head>
<body>			
<center><img draggable='false' width='100' height='100' src=imagess/background/logo.png>
<h1>Test</h1>
<form action="Verification.php" method="POST" />
<input type="TEXT" name="search" autofocus placeholder="Admission no." />
<input type="SUBMIT" name="submit" value="Verify" />
<br /><br />
<input type="button" value="Search Another" style="width:120px; height:20px" onclick="window.location ='Verification.php'" />
</center>
<br />
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
?>
<center>
<table border="10" height="100" cellspacing="5" cellpadding="5" bordercolor='#21DBD9' bgcolor='#E5F4F4'/>
<TR>
<TD><b>ADMISSION NO.</b></TD>
<TD><center><b><font color="red">
 <?php echo $row['adm_no'];?></font><b></center>
 </TD>
 </TR>
 <TR>
<TD><b>BRANCH</b></TD>
<TD><center><b><font color="red">
 <?php echo $row['branch'];?>
 </center></TD>
 </TR>
 <TR>
<TD><b>NAME</b></TD>
<TD><center>
 <?php echo $row['name'];?>
 </center></TD>
 </TR>
<TR>
<TD><b>PHOTO</b></TD>
<TD>
<?php echo "<center><img width='120' height='120' src=imagess/student/".$row['img'].">";?>
</center></TD>
</TR>
<TR>
<TD><b>DATEOFBIRTH</b></TD>
<TD><center>
 <?php echo $row['dob'];?>
 </center></TD>
 </TR>
  <TR>
<TD><b>FATHER/GURDIAN</b></TD>
<TD><center>
 <?php echo $row['fname'];?>
</center></TD>
 </TR>
  <TR>
<TD><b>MOBILE NO</b></TD>
<TD><center>
 <?php echo $row['mb_no'];?>
 </center></TD>
 </TR>
  <TR>
<TD><b>EMAIL</b></TD>
<TD><center>
 <?php echo $row['email'];?>
</center></TD>
 </TR>
<TR>
<TD><b>CORE</b></TD>
<TD><center>
<?php echo $row['core'];?>
</center>
</TD>
</TR>
<TR>
<TD><b>DATEOFADMISSION</b></TD>
<TD><center>
 <?php echo $row['dat_adm'];?>
 </center></TD>
 </TR>
<TR>
<TD><b>DATEOFLEAVING</b></TD>
<TD><center>
 <?php echo $row['dat_lvng'];?>
 </center></TD>
 </TR>
 <TR>
<TD><b>GRADE</b></TD>
<TD><center>
 <?php echo $row['grade'];?>
 </center></TD>
 </TR>
 <TR>
<TD><b>REMARK</b></TD>
<TD><center>
 <?php echo $row['remark'];?>
</center></TD>
 </TR>
 <TR>
<TD><b>CERTIFICATE</b></TD>
<TD><center>
 <?php echo $row['c_issue'];?>
 </center></TD>
 </TR>
 <TR>
<TD><b>SIGN</b></TD>
<TD><center>
 <img width='120' height='30' src=imagess/sign.png>
 </center></TD>
 </TR>
</table>
</form>
<br />
</center>
</body>
</html>
<?php
}		 	
?>

#2

The problem is occurring because you draw the results table without checking how many rows are returned by the query. Have a look at num_rows.


#3

@droopsnoot Thank you for you reply, can you fix it for me? I'm new at this.


#4

Have a read up on the function that I mentioned, see if that gives you enough to have a go. I'm happy to help, but not to just do it for you.


#5

i tried you suggestion, but i'm not able to sort it out. :sweat:


#6

$resultSet = $mysqli->query("SELECT * FROM stud_adm WHERE adm_no = '".$search."' ");

try this...


#7

Show the code you tried, so that someone might see what wasn't correct about it.


#8

Sorry for the late reply issue fixed.


closed #9

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.