View Full Version : alert

04-20-2006, 08:18 PM
Hello everyone! I have a small problem here and I would like you to tell me your suggestions. I have created a login form in my php page. The problem is that this form's action takes you to another page. However I want before the form is submitted to check if the username and password exists in my database. To do so I have included an alert javascript message inside php code AND placed everything onSubmit. Can you please help me? If username and password are correct a new page is displayed else (I must use the alert or a fail page). This is how it looks like with the alert but it doesn't work. :confused:

<form name="form1" method="post" action="/loganswer.php" onSubmit="<?php if ($ena!==$user and $dyo!==$pass) {
echo "<script language=javascript>alert('Please enter a valid username.')</script>";}?>">

04-20-2006, 08:29 PM
you are getting confused between client-side and server-side programming. JS runs on the client. PHP runs on the server. PHP does not know anything about what has been entered into your form until the data is sent to the server. thus, there is no way that PHP can determine if the username exists in the database without first receiving the form data. the traditional requirement is here is that the form be submitted to the server so PHP can access the form data. there are other ways that the client and server can communicate without user intervention, namely AJAX (http://www.adaptivepath.com/publications/essays/archives/000385.php). your question suggests that you are rather new to PHP and as such i would suggest that you not try and tackle AJAX until you have a better understanding of more traditional client/server programming.

04-21-2006, 03:52 PM
Thank you devinemke for your reply but i really don't know what to do now.
Please take a look of this and tell me if i can echo a form in another page when submit is pressed. Will this work? Sorry for bothering with stupid questions!

$ena= $_POST[textfield]; //username from home page
$dyo = $_POST[textfield2]; //password >> >>
$conn = mysql_connect("localhost", "root", "12365875") or die(mysql_error());
mysql_select_db("e-kiosk",$conn) or die(mysql_error());
$sql = "SELECT username,password FROM customers";
$result = mysql_query($sql,$conn) or die(mysql_error());
$user = $row['username']; //username from database
$pass = $row['password']; //password >> >>
if ($ena!==$user and $dyo!==$pass) {



Can i load a whole php page from php code if the condition above is executed? Can this happen with if (isset($_POST['submit'] and how?

04-21-2006, 03:53 PM
look 2 threads down .. ive replied...

04-21-2006, 03:54 PM