<?php $username = 'user'; $pwd = "" $query1 = "SELECT passord FROM user WHERE username='$username'; $results1 = mysql_query($query1); if (!mysql_num_rows($results1) == 0) { $pwd = password; ?> <script language="JavaScript"> window.alert("Password: " <?php echo $pwd; ?> ); </script>
How can I pass the password variable from MySQL, assign it to php variable $pwd and then pass it to javascript in alert popup?
thanks
Put the php echo within the quotes:
window.alert("Password: <?php echo $pwd; ?>");
Depending on what sort of data might be in $pwd, it might be better to do:
window.alert("Password: <?php echo htmlspecialchars($pwd, ENT_QUOTES); ?>");
$query1 = "SELECT password FROM useraccount WHERE username='$username'"; $results1 = mysql_query($query1); if (mysql_num_rows($results1) != '0') { while(list($password) = mysql_fetch_Array($results1)) { ?> <script language="JavaScript"> window.alert("Password: <?php echo $password; ?>" ); </script> <?php } }
The password variable cannot be retrieved and display on alert. What's wrong with the code?