Grumps Posted December 1, 2015 Share Posted December 1, 2015 <?php ob_start(); $host="localhost"; // Host name $username="*****"; // Mysql username $password="*******"; // Mysql password $db_name="*****"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"] = $username; $_SESSION["mypassword"] = $mypassword; header("location:main.php"); } { echo "<script language=\"JavaScript\">\n"; echo "alert('Incorrect Username or Password');\n"; echo "window.location='index.php'"; echo "</script>"; } ob_end_flush(); ?> I have a login and I want the incorrect login alert box changed to a yes / no confirm box. If you put in an incorrect username and/or password you should get a confirm box "Do you have an account?" (yes / No). If yes, alert box "Please check your login details" else alert box "Username = cash\nPassword = cash" Any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/299614-call-alert-box-from-confirm-box/ Share on other sites More sharing options...
benanamen Posted December 1, 2015 Share Posted December 1, 2015 (edited) You are using deprecated code that will not work at all in the latest version of Php. You need to be using PDO with prepared statements or Mysqli. Edited December 1, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/299614-call-alert-box-from-confirm-box/#findComment-1527384 Share on other sites More sharing options...
ginerjm Posted December 1, 2015 Share Posted December 1, 2015 IMHO - When a user enters incorrect credentials you should simply put back the login screen with/without the incorrect userid and NO password and a message saying that the entries were invalid. This way they get to try again without having to click on boxes. Don't send back the password, just the userid entry to avoid multiple transmissions of a possibly valid pswd. 1 Quote Link to comment https://forums.phpfreaks.com/topic/299614-call-alert-box-from-confirm-box/#findComment-1527402 Share on other sites More sharing options...
mikesta707 Posted December 2, 2015 Share Posted December 2, 2015 You are indeed using deprecated code, but this is really a Javascript question. If you want a confirmation box instead of an alert you should use the confirm function in javascript, rather than the alert function. See here: http://www.w3schools.com/jsref/met_win_confirm.asp An example: var txt; var r = confirm("Do you have an account?"); if (r == true) { window.location = "login.php"; } else { window.location = "register.php"; } This is NOT tested btw. Quote Link to comment https://forums.phpfreaks.com/topic/299614-call-alert-box-from-confirm-box/#findComment-1527445 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.