Jump to content

PHP help need urgently


akhilkumar332

Recommended Posts

 i got few problems on my php file... the prob is i can able to search and retrieve data using adm_no value on my php bt when i enter...some other value which is not in my database....it should give me an arror "No Such Data Found".........this is my prob.....below is php file scripts ...plz look into it and solve my problem...m noob at this joy.png?v=3 ....i just managed to get till here

note: I want all the data to shown up in the Table only not anywhere else!!!

plz help 

Thank you!!!

 

<?php

include_once("bg.php");
ob_start();
session_start();
 
$output = NULL;
 
if(isset($_POST['submit'])){
//Connect to dataBase
$mysqli=mysqli_connect("localhost","akhil","qwerty123","u761479816_bdata");
 
$search = $mysqli->real_escape_string($_POST['search']);
 
//query the Database
$resultSet = $mysqli->query("SELECT * FROM stud_adm WHERE adm_no = '$search'");
 
 
if($resultSet->num_rows > 0){
while($rows = $resultSet->fetch_assoc())
{
$adm_no = $rows['adm_no'];
$name = $rows['name'];
$img = $rows['img'];
$dob = $rows['dob'];
$fname = $rows['fname'];
$mb_no = $rows['mb_no'];
$email = $rows['email'];
$core = $rows['core'];
$d_passing = $rows['d_passing'];
$grade = $rows['grade'];
$remark = $rows['remark'];
$c_issue = $rows['c_issue'];
 
 
$output = "
Admission No: $adm_no<br />
Name: $name<br />
Photo: <img src='./imagess/student/".$rows ['img']."' height='70' width='70'><br />
Date of Birth: $dob<br />
Father/Gurdian Name: $fname<br />
Mobile No: $mb_no<br />
Email: $email<br />
Core: $core<br />
Date of Passing: $d_passing<br />
Grade: $grade<br />
Remark: $remark<br />
Certificate: $c_issue";
}
}else{
$output = "No Data Found";
}
}
?>
<center><img draggable='false' width='100' height='100' src=imagess/background/logo.png>
<center>
<h1>Techwell Institute</h1>
<center>
<form action="Verification.php" method="POST">
<input type="TEXT" name="search" />
<input type="SUBMIT" name="submit" value="Verify">
<br /><br />
<table border="10" height="100" cellspacing="5" cellpadding="5" bordercolor='#21DBD9' bgcolor='#E5F4F4'>
<TR>
<TD><b>ADMISSION NO.</b></TD>
<TD><center>
 <?php echo $adm_no ?>
 </TR>
 <TR>
<TD><b>NAME</b></TD>
<TD><center>
 <?php echo $name ?>
 </TR>
<TR>
<TD><b>PHOTO</b></TD>
<TD><center>
<?php echo "<img width='70' height='70' src=./imagess/student/".$img.">";?>
</TD>
</TR>
<TR>
<TD><b>DATEOFBIRTH</b></TD>
<TD><center>
 <?php echo $dob ?>
 </TR>
  <TR>
<TD><b>FATHER/GURDIAN</b></TD>
<TD><center>
 <?php echo $fname ?>
 </TR>
  <TR>
<TD><b>MOBILE NO</b></TD>
<TD><center>
 <?php echo $mb_no ?>
 </TR>
  <TR>
<TD><b>EMAIL</b></TD>
<TD><center>
 <?php echo $email ?>
 </TR>
<TR>
<TD><b>CORE</b></TD>
<TD><center>
<?php echo $core ?>
</center>
</TD>
</TR>
<TR>
<TD><b>DATEOFPASSING</b></TD>
<TD><center>
 <?php echo $d_passing ?>
 </TR>
 <TR>
<TD><b>GRADE</b></TD>
<TD><center>
 <?php echo $grade ?>
 </TR>
 <TR>
<TD><b>REMARK</b></TD>
<TD><center>
 <?php echo $remark ?>
 </TR>
 <TR>
<TD><b>CERTIFICATE</b></TD>
<TD><center>
 <?php echo $c_issue ?>
 </TR>
</table>
</form>
<input type="button" value="Search Another" style="width:120px; height:30px" onclick="window.location ='Verification.php'">
<br /><br />
</center>
<?php echo $output; ?>
 
 
I have also attached my  php file!!!
Link to comment
Share on other sites

It looks like it does show that "no data found" message: at the bottom of the form after the table.

 

Problem is you aren't deciding whether to show the table or to show the message depending on the results. You do everything and hope that all the variables have values.

You need something like that "if num_rows > 0" you had earlier but covering the rest of the code and output too.

Link to comment
Share on other sites

Well, if you want to work with PHP then you're going to have to learn some. I don't know about the quality but I'm sure there are plenty of videos on YouTube to learn from.

 

Right now your code looks like

<?php

if form was submitted {
	query
	if results {
		gather data into variables
		create $output with data
	} else {
		create $output with error message
	}
}
?>
show form, table, and $output
It needs to look more like

<?php

if form was submitted {
	query
	if results {
		gather data into variables
		create $output with data
	} else {
		create $output with error message
	}
}

?>
show form
<?php

if form was submitted {

?>
show table and/or $output
<?php

}

?>
Link to comment
Share on other sites

one more problem

if i enter the value...which is present in database....if gives me the output correctly

 

But when i enter some other value it gives message "Undefined Variable" for all the rows

 

Notice: Undefined variable: adm_no in C:\xampp\htdocs\bypass-student-enroll\qwerty.php on line 59

 

Just give me the format to  define the variable for the data present in table and i will do 

Link to comment
Share on other sites

Now it working fine after little modification

 

bt one last problem is.....i should get "No Such Data Found" if i enter a wrong value(wrong admission no)

Plz help me...!!!

Thank you 

<?php
include_once("bg.php");
ob_start();
session_start();

if(isset($_POST['submit'])){
	//Connect to dataBase
	$mysqli=mysqli_connect("localhost","akhil","qwerty123","u761479816_bdata");
	
	$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);
}
	?>			
<center><img draggable='false' width='100' height='100' src=imagess/background/logo.png>
<center>
<h1>Techwell Institute</h1>
<center>
<form action="qwerty.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 ='qwerty.php'">
</center>
<br />
<?php
if(isset($_POST['submit'])){
?>
<center>
<table border="10" height="100" cellspacing="5" cellpadding="5" bordercolor='#21DBD9' bgcolor='#E5F4F4'>
<TR>
<TD><b>ADMISSION NO.</b></TD>
<TD><center>
 <?php echo $row['adm_no'];?>
 </TR>
 <TR>
<TD><b>NAME</b></TD>
<TD><center>
 <?php echo $row['name'];?>
 </TR>
<TR>
<TD><b>PHOTO</b></TD>
<TD><center>
<?php echo "<center><img width='120' height='120' src=imagess/student/".$row['img'].">";?>
</TD>
</TR>
<TR>
<TD><b>DATEOFBIRTH</b></TD>
<TD><center>
 <?php echo $row['dob'];?>
 </TR>
  <TR>
<TD><b>FATHER/GURDIAN</b></TD>
<TD><center>
 <?php echo $row['fname'];?>
 </TR>
  <TR>
<TD><b>MOBILE NO</b></TD>
<TD><center>
 <?php echo $row['mb_no'];?>
 </TR>
  <TR>
<TD><b>EMAIL</b></TD>
<TD><center>
 <?php echo $row['email'];?>
 </TR>
<TR>
<TD><b>CORE</b></TD>
<TD><center>
<?php echo $row['core'];?>
</center>
</TD>
</TR>
<TR>
<TD><b>DATEOFPASSING</b></TD>
<TD><center>
 <?php echo $row['d_passing'];?>
 </TR>
 <TR>
<TD><b>GRADE</b></TD>
<TD><center>
 <?php echo $row['grade'];?>
 </TR>
 <TR>
<TD><b>REMARK</b></TD>
<TD><center>
 <?php echo $row['remark'];?>
 </TR>
 <TR>
<TD><b>CERTIFICATE</b></TD>
<TD><center>
 <?php echo $row['c_issue'];?>
 </TR>
</table>
</form>
<br />
</center>
<?php
}		 	
?>
Link to comment
Share on other sites

Well you removed all that code so it won't do that anymore. Why did you do that? You have the table showing if the form was submitted but it needs to show only if the form was submitted and there were results; then you show a message if the form was submitted and there were not results.

 

As in

if form was submitted {
	get results
	if there are results {
		show table
	} else {
		show message
	}
}
Link to comment
Share on other sites

You have several other problems that have not been mentioned.

 

1. if(isset($_POST['submit']))  SHOULD BE if ($_SERVER['REQUEST_METHOD'] == 'POST')

2. You are using the obsolete <center> tag. On top of that, you are missing several closing </center> tags. You should be using CSS.

3. You are missing several closing </td> tags. If you used a proper IDE with syntax highlighting you would have seen that.

4. Using a <table> for formating went out in the 90's. Again, you need to use CSS

5. You need to use Prepared Statements

6. You have your closing </form> completely split in the logic from your <form>

7. Having two submit checks is redundant and completely unnecessary

8. You need to use htmlentities on your DB output.

9. You are missing numerous basic html tags. Doc type, body...etc.. 

10. It's pretty clear you need to take some time and learn the basics before trying to move forward.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.