akhilkumar332 Posted November 28, 2016 Share Posted November 28, 2016 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 ....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!!! Verification.php Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/ Share on other sites More sharing options...
requinix Posted November 28, 2016 Share Posted November 28, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539763 Share on other sites More sharing options...
akhilkumar332 Posted November 28, 2016 Author Share Posted November 28, 2016 #requinix Yes thats exactly my problem is!!! Could u plz correct it and resend... I just need the output to be displayed in table only not anywhere else!!! Plz help me with this....i need this Thank you Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539768 Share on other sites More sharing options...
requinix Posted November 28, 2016 Share Posted November 28, 2016 No. We're not going to fix it for you. Try making the changes I said yourself. If you have problems, post the code you have and a description of what's happening. Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539769 Share on other sites More sharing options...
akhilkumar332 Posted November 28, 2016 Author Share Posted November 28, 2016 ok i will try...just tell i have to do...in detail Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539770 Share on other sites More sharing options...
requinix Posted November 28, 2016 Share Posted November 28, 2016 How much of the code there now did you write? Do you know any PHP? Have you used things like if statements? Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539777 Share on other sites More sharing options...
akhilkumar332 Posted November 28, 2016 Author Share Posted November 28, 2016 firstly idk php.....i just managed it from youtube.....n i managed to pull data from database Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539779 Share on other sites More sharing options...
requinix Posted November 28, 2016 Share Posted November 28, 2016 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 $outputIt 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539783 Share on other sites More sharing options...
akhilkumar332 Posted November 28, 2016 Author Share Posted November 28, 2016 Thank you.... i will do...as u said.... will post back if there any prob Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539786 Share on other sites More sharing options...
akhilkumar332 Posted November 28, 2016 Author Share Posted November 28, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539796 Share on other sites More sharing options...
requinix Posted November 28, 2016 Share Posted November 28, 2016 That code is running because of the if form was submitted {right? But the variables will only be defined if there were results. So that "form was submitted" condition should be modified so that the form has to have been submitted and there must have been results. Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539798 Share on other sites More sharing options...
akhilkumar332 Posted November 28, 2016 Author Share Posted November 28, 2016 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539805 Share on other sites More sharing options...
requinix Posted November 29, 2016 Share Posted November 29, 2016 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539817 Share on other sites More sharing options...
benanamen Posted November 29, 2016 Share Posted November 29, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539818 Share on other sites More sharing options...
akhilkumar332 Posted November 29, 2016 Author Share Posted November 29, 2016 benanamen...i just checked and fixed all closing td and center tags.... and also fixed most of the point u mentioned above... Thank you for suggesting and Thank you requinix My Problem is solved now Quote Link to comment https://forums.phpfreaks.com/topic/302630-php-help-need-urgently/#findComment-1539822 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.