jushiro Posted October 6, 2011 Share Posted October 6, 2011 I've Made a php code.. <?php switch ($_POST['test']) { case 'reject': $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbprof", $con); foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM registeredprof WHERE fullname='$checkbox'"; } $result=mysql_query($sql); if(mysql_num_rows($result)) { foreach ($_POST['list'] as $checkbox) { mysql_query("DELETE FROM registeredprof WHERE fullname='$checkbox'") or die(mysql_error); } echo '<script type="text/javascript"> {alert("Instructor Removed!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=delins.php">'; } else { echo '<meta http-equiv="REFRESH" content="0;url=delins.php">';} } ?> ITS WORKING in Google Chrome. But once i run it on Mozilla Firefox. Its displays Blank page.. Is this a problem in my codes? or is there any codes i can put to it to make it run to mozilla? Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/ Share on other sites More sharing options...
AyKay47 Posted October 6, 2011 Share Posted October 6, 2011 what does a view source show? have you tried using firebug? Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276488 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2011 Share Posted October 6, 2011 Your form is probably not submitting what you think it is. What does the following (added immediately after the <?php tag) show - echo '<pre>',print_r($_POST,true),'</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276489 Share on other sites More sharing options...
jushiro Posted October 6, 2011 Author Share Posted October 6, 2011 @aykay -- waaaaaaaaaa! it didnt show any codes in page source. does it read php? @PFMabismad.. Hmm yes it did Submit. When i inserted your code it did show the values of my checkbox. And yea, its working in google chrome. but when i use Mozilla it shows a blank page. why is that? do i need to add something to my mozilla? Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276491 Share on other sites More sharing options...
AyKay47 Posted October 6, 2011 Share Posted October 6, 2011 can i ask why a switch is necessary here? If you are only comparing one value.. a simple if statement is fine.. most likely the switch statement is not being met for some reason.. ergo its not outputing anything to the browser.. I would try something like this perhaps.. if(!empty($_POST['test'])){ if($_POST['test'] == "reject"){ //insert your code here }else{ echo "failed"; } } Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276494 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 6, 2011 Share Posted October 6, 2011 use this code, try it. <?php if(!empty($_POST['test'])){ if($_POST['test'] == "reject"){ $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbprof", $con); foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM registeredprof WHERE fullname='$checkbox'"; } $result=mysql_query($sql); if(mysql_num_rows($result)) { foreach ($_POST['list'] as $checkbox) { mysql_query("DELETE FROM registeredprof WHERE fullname='$checkbox'") or die(mysql_error); } echo '<script type="text/javascript"> {alert("Instructor Removed!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=delins.php">'; } else { echo '<meta http-equiv="REFRESH" content="0;url=delins.php">';} } }else{ echo "failed"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276508 Share on other sites More sharing options...
jushiro Posted October 6, 2011 Author Share Posted October 6, 2011 Still shows blank page as a result ( IN MOZILLA) By the way.. I've Used this code that's why i used SWITCH for that. <?php $host="localhost"; $username="root"; $password=""; $db_name="dbprof"; $tbl_name="teacher"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); echo "<table border=\"5\" width=\"400\" >"; echo "<tr><th>List of Instructor</th>"; if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { echo "<tr><td>"; echo "<input type='checkbox' name='list[]' value='".$row['fullname']."' name='".$row['fullname']."'>" .$row['fullname']."<br/></td>"; echo "</tr>"; } } else { echo "<tr><td align=\"center\"> No Instructor to be Approve / Reject </td></tr>"; } echo '</form>'; ?> So.. There' output only shows in google chrome. hope you could help me. Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276513 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2011 Share Posted October 6, 2011 You have two name="..." attributes in the <input > field, making the HTML invalid. You also don't have a <form ...> tag, unless you deleted that from the post. Different browsers handle HTML errors differently. Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276535 Share on other sites More sharing options...
AyKay47 Posted October 6, 2011 Share Posted October 6, 2011 wish you would have posted that code from the beginning.. Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1276536 Share on other sites More sharing options...
jushiro Posted October 8, 2011 Author Share Posted October 8, 2011 Sorry for that.. @PFMaBismad -- hmm i did make a form.. and remove that double name = "...." Still it show a blank page when i loaded it to Mozilla. i dont know what to do.. Someone help pls. Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1277224 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2011 Share Posted October 8, 2011 What does a 'view source' in your browser of the form page show and what does a 'view source' in your browser of the blank page show? The short answer to all this is - we only see the information you supply in your posts. Without all the actual code necessary to reproduce the problem, we cannot really help. Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1277242 Share on other sites More sharing options...
jushiro Posted October 8, 2011 Author Share Posted October 8, 2011 Here's my whole code. <html> <head> <title>Teacher</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- #apDiv2 { position:absolute; width:200px; height:115px; z-index:1; left: 217px; top: 163px; } --> </style> <style type="text/css"> <!-- #apDiv1 { position:absolute; width:184px; height:35px; z-index:3; left: 833px; top: 504px; } #apDiv2 { position:absolute; width:200px; height:115px; z-index:4; left: 326px; top: 211px; } #apDiv3 { position:absolute; width:188px; height:36px; z-index:4; left: 825px; top: 486px; } #apDiv4 { position:absolute; width:186px; height:40px; z-index:5; left: 824px; top: 300px; } #apDivtest { position:absolute; width:180px; height:39px; z-index:6; left: 824px; top: 336px; } #apDiv6 { position:absolute; width:187px; height:32px; z-index:7; left: 824px; top: 297px; } #apDiv5 { position:absolute; width:180px; height:35px; z-index:8; left: 834px; top: 225px; } #apDiv7 { position:absolute; width:181px; height:35px; z-index:9; left: 240px; top: 250px; } #apDiv8 { position:absolute; width:180px; height:30px; z-index:10; left: 240px; top: 213px; } #apDiv9 { position:absolute; width:181px; height:32px; z-index:11; left: 825px; top: 339px; } #apDiv10 { position:absolute; width:339px; height:41px; z-index:9; left: 285px; top: 246px; } #apDiv11 { position:absolute; width:171px; height:29px; z-index:9; left: 835px; top: 299px; } #apDiv12 { position:absolute; width:176px; height:36px; z-index:10; left: 835px; top: 262px; } #apDiv13 { position:absolute; width:184px; height:37px; z-index:1; left: -1px; top: -52px; } #apDiv14 { position:absolute; width:200px; height:115px; z-index:11; left: 101px; top: 165px; } --> </style></head> <img src="images/approvereject2.jpg" width="998" height="651" /> <form name="formout" method="post" action="logout2.php"> <div id="apDiv1"><input type="image" src="images/logout.png" name="logout" width="170" height="35" border="0"> </div></form> <form name="formh" method="post" action="teacherpage.php"> <div id="apDiv5"><input type="image" src="images/home.png" name="xD" width="170" height="35" border="0" ></div></form> <form name="formapprove" method="POST" action="valval3.php" > <div id="apDiv12"><input type="image" src="images/Approve.png" name="test" value="approve" width="170" height="35" border="0" > </div> <div id="apDiv11"> <input type="image" src="images/reject.png" name="test" width="170" height="35" border="0" value="reject"> </div> <div id="apDiv14"> <?php $host="localhost"; $username="root"; $password=""; $db_name="dbreg"; $tbl_name="account"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); echo "<table border=\"5\" width=\"400\" >"; echo "<tr><th>List of Student to be approve</th>"; if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { echo "<tr><td>"; echo "<input type='checkbox' name='list[]' value='".$row['Username']."'>" .$row['gname']. " ".$row['mname']. " " .$row['famname']. "<br/></td>"; echo "</tr></input>"; } } else { echo "<tr><td align=\"center\"> No Student to be Approve / Reject </td></tr>"; } ?> </form> </div> </head> </body> </html> VALVAL3.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } switch ($_POST['test']) { case 'approve': mysql_select_db("dbreg", $con); $sql="SELECT * FROM account where Username='$checkbox'"; foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM account WHERE Username='$checkbox'"; } $result=mysql_query($sql); if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $username = $row['Username']; $password = $row['Password']; $gname = $row['gname']; $mname = $row['mname']; $famname = $row['famname']; $sec = $row['sec']; $studnum = $row['studnum']; $fullname = "" .$row['famname']. ", " .$row['gname']. " " .$row['mname']. "."; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $gname = stripslashes($gname); $famname = stripslashes($famname); $gname = mysql_real_escape_string($gname); $famname = mysql_real_escape_string($famname); $mname = stripslashes($mname); $mname = mysql_real_escape_string($mname); foreach ($_POST['list'] as $checkbox) { mysql_query("INSERT INTO dbaccount (Username, Password, gname, famname, mname, sec, studnum, fullname) VALUES ('$checkbox', '$password', '$gname', '$famname', '$mname', '$sec', '$studnum', '$fullname')") or die(mysql_error); mysql_query("DELETE FROM account WHERE Username='$checkbox'") or die(mysql_error); } echo '<script type="text/javascript"> {alert("Approved!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; mysql_close($con); } } else { echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } break; case 'reject': mysql_select_db("dbreg", $con); foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM account WHERE Username='$checkbox'"; } $result=mysql_query($sql); if(mysql_num_rows($result)) { foreach ($_POST['list'] as $checkbox) { mysql_query("DELETE FROM account WHERE Username='$checkbox'") or die(mysql_error); } echo '<script type="text/javascript"> {alert("Rejected!");} </script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } else { echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } } ?> There.. This codes works at Google Chrome.. But not in Mozilla Firefox. I Cant write the page source for the Working one' because yea' its working. it return to the same page when it is approved. But in the browser that show's a blank page which is Mozilla Firefox. i cant write the page source because its blank. Nothing to show. (' does firefox not accepting switch statement? Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1277244 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2011 Share Posted October 8, 2011 Without the 'view source' in your bowser of your form page (no one asked for the raw .php file), I'm going to guess that some of your database data contains htmlentities that is breaking the HTML of your page. All data and content (that is not specifically HTML tags) should be passed through the htmlentities function with the second parameter set to ENT_QUOTES so that the data and content does not break the HTML on your page. Edit: If the first code you did post is the 'view source' in your browser, that would mean that php is not installed and running on your server or you browsed directly to the .php file through the file system, instead of entering the URL of the file in your browser's address bar. Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1277249 Share on other sites More sharing options...
jushiro Posted October 12, 2011 Author Share Posted October 12, 2011 Hi, i mange to solve my problem.. Thx everyone for the reply.. Anyway, this is how i done it. I tried to use the GET method and i notice there are 2 variable outputted. so i return it to POST and made this code if(isset($_POST['approve_x'], $_POST['approve_y'])) { Instead of switch.. hmm idk why.. but i think old browser like mozilla and IE doesnt have that automatic catch for variables? xD.. but anyway. THX AGAIN! Quote Link to comment https://forums.phpfreaks.com/topic/248560-help/#findComment-1278533 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.