jushiro Posted October 13, 2011 Share Posted October 13, 2011 Im having a problem in popup box.. i made a checkbox in a loop.. then after a success loop ive set a code for a popupbox. echo '<script type="text/javascript"> {alert("Rejected!");} </script>'; But when a user checked 2 check boxes.. it would also popup a 2 popup box.. How can i make my code only popup once even if it selects multiple checkboxes? Quote Link to comment https://forums.phpfreaks.com/topic/249042-popup-boxes/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 13, 2011 Share Posted October 13, 2011 the code you put there cannot help you. we need more code... anyway, why is the alert function in brackets? Quote Link to comment https://forums.phpfreaks.com/topic/249042-popup-boxes/#findComment-1279004 Share on other sites More sharing options...
jushiro Posted October 13, 2011 Author Share Posted October 13, 2011 Because i use PHP for this.. anyway this is the whole code. <?php session_start(); if(isset($_SESSION['uname2']) || ($_SESSION['section'])){ $con = mysql_connect("localhost","root",""); if(isset($_POST['approve_x'], $_POST['approve_y'])) { mysql_select_db("dbreg", $con); foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM account WHERE Username='$checkbox'"; $result=mysql_query($sql); 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['fullname']; $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); 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">'; } } } elseif(isset($_POST['reject_x'], $_POST['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)) { 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">'; } } } else { header("location:failunautho.php");; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249042-popup-boxes/#findComment-1279009 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 13, 2011 Share Posted October 13, 2011 try this <?php session_start(); $appr = 0; $reje = 0; if(isset($_SESSION['uname2']) || ($_SESSION['section'])){ $con = mysql_connect("localhost","root",""); if(isset($_POST['approve_x'], $_POST['approve_y'])) { mysql_select_db("dbreg", $con); foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM account WHERE Username='$checkbox'"; $result=mysql_query($sql); 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['fullname']; $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); 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); $appr++; } } } elseif(isset($_POST['reject_x'], $_POST['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)) { mysql_query("DELETE FROM account WHERE Username='$checkbox'") or die(mysql_error); $reje++; } else { echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } } } if($appr > 1) { echo '<script type="text/javascript">alert("Approved!");</script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } if($reje > 1) { echo '<script type="text/javascript">alert("Rejected!");</script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } else { header("location:failunautho.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249042-popup-boxes/#findComment-1279015 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 13, 2011 Share Posted October 13, 2011 Sorry, there was syntax error on the previous code, here is the updated one. <?php session_start(); $appr = 0; $reje = 0; if(isset($_SESSION['uname2']) || isset($_SESSION['section'])) { $con = mysql_connect("localhost","root",""); if(isset($_POST['approve_x']) && isset($_POST['approve_y'])) { mysql_select_db("dbreg", $con); foreach ($_POST['list'] as $checkbox) { $sql="SELECT * FROM account WHERE Username='$checkbox'"; $result=mysql_query($sql); 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['fullname']; $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); 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); $appr++; } } } elseif(isset($_POST['reject_x']) && isset($_POST['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)) { mysql_query("DELETE FROM account WHERE Username='$checkbox'") or die(mysql_error); $reje++; } else { echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } } } if($appr > 1) { echo '<script type="text/javascript">alert("Approved!");</script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } if($reje > 1) { echo '<script type="text/javascript">alert("Rejected!");</script>'; echo '<meta http-equiv="REFRESH" content="0;url=approvereject2.php">'; } } else { header("location:failunautho.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249042-popup-boxes/#findComment-1279021 Share on other sites More sharing options...
jushiro Posted October 13, 2011 Author Share Posted October 13, 2011 Yea thx for that! i noticed that too.. so i edited it. and replace $appr = 0; $reje = 0; TO $appr = 1; $reje = 1; Because when user checked 1 values.. a blank page will show. Hey! thx a lot for the help.. Quote Link to comment https://forums.phpfreaks.com/topic/249042-popup-boxes/#findComment-1279029 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 13, 2011 Share Posted October 13, 2011 oh, haha forgot about that. no prob (: Quote Link to comment https://forums.phpfreaks.com/topic/249042-popup-boxes/#findComment-1279033 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.