Jump to content

Call alert box from confirm box


Grumps

Recommended Posts

<?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.

 

 

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

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.