moneeshot Posted January 24, 2009 Share Posted January 24, 2009 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(); ?> Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/ Share on other sites More sharing options...
nuttycoder Posted January 24, 2009 Share Posted January 24, 2009 you could put the password inside a JavaScript alert this will cause a popup with the password and an ok button see a demo at http://www.tizag.com/javascriptT/javascriptalert.php Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745053 Share on other sites More sharing options...
moneeshot Posted January 24, 2009 Author Share Posted January 24, 2009 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 Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745060 Share on other sites More sharing options...
nuttycoder Posted January 24, 2009 Share Posted January 24, 2009 you can place php inside javascript easily its hard the other way round. <script type="text/javascript"> alert("Your password is <?php echo $row->password;?>"); </script> Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745066 Share on other sites More sharing options...
moneeshot Posted January 24, 2009 Author Share Posted January 24, 2009 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. Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745081 Share on other sites More sharing options...
nuttycoder Posted January 24, 2009 Share Posted January 24, 2009 Sorry not to sure what you mean. Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745089 Share on other sites More sharing options...
moneeshot Posted January 24, 2009 Author Share Posted January 24, 2009 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 Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745094 Share on other sites More sharing options...
nuttycoder Posted January 24, 2009 Share Posted January 24, 2009 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745102 Share on other sites More sharing options...
moneeshot Posted January 24, 2009 Author Share Posted January 24, 2009 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 Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745106 Share on other sites More sharing options...
nuttycoder Posted January 24, 2009 Share Posted January 24, 2009 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. Link to comment https://forums.phpfreaks.com/topic/142218-solved-login-forgot-password-response-using-msg-box/#findComment-745110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.