Jump to content

[SOLVED] login-forgot password response using msg box


moneeshot

Recommended Posts

I created a simple login for users I add to this site, no uninvited guests. The echo response I have now displays the user password to a page, it works fine but I would Prefer the password displayed in a message box with an OK button. Don't know what script you need so I'll include the whole page. Help would be much appreciated.

 

<?php

ob_start();

$host="localhost"; // Host name

$username="myName"; // Mysql username

$password="myPassword"; // Mysql password

$db_name="login"; // Database name

$tbl_name="loginMembers"; // Table name

 

 

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// Define username  passHelp from txtBox name

$passHelp=$_POST['passHelp'];

 

// To protect MySQL injection

$passHelp = stripslashes($passHelp);

$passHelp = mysql_real_escape_string($passHelp);

 

 

 

$sql2="SELECT email,password FROM $tbl_name WHERE $tbl_name.email='$passHelp'";

$passwordRecover=mysql_query($sql2);

 

$st=mysql_query($sql2);

$recs=mysql_num_rows($st);

$row=mysql_fetch_object($st);

$em=$row->username;// email is stored to a variable

 

// Mysql_num_row is counting table row

$count=mysql_num_rows($st);

 

// If result matched, row must be 1 row

 

if($count==1){

// Register $myusername, $mypassword

session_register("myusername");

echo "<center><font size='5'>Your password is: $row->password </font><br><input type='button' value='Back' onClick='history.go(-1)'></center>";

}

else {

echo "Wrong E-mail <br><input type='button' value='Back' onClick='history.go(-1)'>";

}

 

ob_end_flush();

 

?>

the code seems easy enough as far as creating the msg box, what about the password itself

can I use

 

"alert('$row->password')"

 

do I need to create a variable in the Jscript,

if so will it recognise the PHP($row->password') in the Jscript.

Thanks for the quick response, monee

I realize I'm going in a slightly different and possibly more confusing direction but I am playing and trying to learn, this is what I did.

 

 

if($count==1){

// Register $myusername, $mypassword

session_register("myusername");

echo "<script type='text/javascript'>

alert('Your password is $row->password')</script>";

}

else {

echo "Wrong E-mail <br><input type='button' value='Back' onClick='history.go(-1)'>";

}

 

 

it works fine except it transfers the msg box to another page, as is the echo, I guess.

any ideas on how to show the box on the same page as the request was sent?

thanks again.

the original code sent "your password is whatever" with a back button to a standard blank echo page.

 

how it is now it sends the msg box to that same echo page. I'm appearantly new to PHP and not sure how to describe this. I tried adding

 

if($count==1){

// Register $myusername, $mypassword

session_register("myusername");

header("location:index.php");

echo "<script type='text/javascript'>

alert('Your password is $row->password')</script>";

}

 

 

that of course refreshed the page so that doesnt work.

I need it to display the msg box without it going to a different page.

if this helps understand my problem great but if not I do appreciate the help nuttycoder, I'll keep plug'n away and see what happens

No I get what you mean now.

 

Try This when ok is pressed the page is moved to index.php

 

<?php
echo "<script type='text/javascript'>";
echo "alert('Your password is $row->password');";
echo "window.location.href = 'index.php';";
echo "</script>";
?>

Its all about syntax.

Thank you very much

I'm going with that.

 

I tried this before you replied

 

include ("index.php");

echo "<script type='text/javascript'>

alert('Your password is $row->password')</script>";

 

odd, but it worked, the code you supplied is cleaner so I'm going with that.

many thanks

 

 

yeah your code includes the index file making any code on that page available to the current page but can have adverse effects.

 

I try to separate my code even though I could have wrote it in a single echo makes it easy to debug if anything goes wrong.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.