View Full Version : Create alert box in PHP
devil_vin
09-07-2007, 08:02 AM
I would like to transform the following php statement in order to get displaying in alert box.
die("The email address '" . $_POST['email'] ."' is already registered");
I tried to transform it with print statement but seems like not work.
print "<script type=\"text/javascript\">";
print "alert('The email address '" . $_POST['email'] ."' is already registered')";
print "</script>";
jonnyynnoj
09-07-2007, 06:13 PM
print '<script type="text/javascript">';
print 'alert("The email address '. $_POST['email'].' is already registered")';
print '</script>';
The above works for me. Just used single quotes for print and got rid of the backslashes.
Better:
?>
<script type="text/javascript">
alert("The email address <?php echo $_POST['email']; ?> is already registered.");
history.back();
</script>
<?php
devil_vin
09-08-2007, 03:05 AM
Better:
?>
<script type="text/javascript">
alert("The email address <?php echo $_POST['email']; ?> is already registered.");
history.back();
</script>
<?php
Thanks...my screen can remain in signup page.However,why data still insert into database for twice?
<?php
//ini_set("include_path", "path/to/language/file");
include ('dbconn.cfg');
//global variable
$tbl_name = "member";
//$table2 = "registered_member";
//Random confirmation code
//$confirm_code = md5(uniqid(rand()));
//This code runs if the form has been submitted
if (isset($_POST['submit']))
{
// checks if the email address is alredy registered
//if (!get_magic_quotes_gpc())
//{
//$_POST['email'] = addslashes($_POST['email']);
//}
$emailcheck = $_POST['email'];
$check = mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0)
{
?>
<script type="text/javascript">
alert("The email address <?php echo $_POST['email']; ?> is already registered.");
history.back();
</script>
<?php
//die("The email address '" . $_POST['email'] ."' is already registered");
//print '<script type="text/javascript">';
//print 'alert("The email address ' . $_POST['email'] .' is already registered")';
//print '</script>';
}
// encrypt the password
$pass1 = md5($pass1);
//if (!get_magic_quotes_gpc())
//{[]
//pass1 = addslashes($pass1);
//$_POST['member_id'] = addslashes($_POST['member_id']);
//Insert record to database
$insert = mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
VALUES ('" . $_POST['name'] . "','" . $_POST['email'] .
"', '" . $_POST['pass1'] . "','" . $_POST['tel'] . "','" . $_POST['address'] .
"')") or die(mysql_error());
// }
//if successfully inserted,send confirmation link to email
if ($insert)
{
//echo "Thank for your registration!";
//header("Location: http://localhost/www/index.php?frame=thankyou");
$redirectUrl = "http://localhost/www/index.php?frame=thankyou";
print "<script type=\"text/javascript\">";
print "window.location.href = '$redirectUrl'";
print "</script>";
/*
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "admin";// SMTP username
$mail->Password = "itc309";// SMTP password
//$mail->SetLanguage("en","phpmailer/language");
//compose mail
$mail->From = "admin@localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin@localhost.com", "cinema admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
//if not found
else
{
echo "Not found your email in our database";
}
if your email successfully sent
if ($sentmail)
{
echo "Your confirmation link has been sent to your email address.";
}*/
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>New User Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function formSubmit()
{
window.event.returnValue = false;
if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) |
(!form1.address.value)){alert("You did not complete all of the required fields");}
else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12)
{alert("Password must be within 6-20 characters!");form1.pass1.focus()}
else if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();}
else window.event.returnValue = true;
}
</script>
</head>
<body bgcolor="#000000">
<div align="center"></div>
<table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
<tr>
<td width="2%" rowspan="4"> </td>
<td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
</tr>
<tr>
<td height="315" bgcolor="#CCCCFF">
<div align="left">
<table width="100%" border="0">
<tr>
<td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member
Registration</font></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
<tr>
<td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important
Notice:</strong></em></font> </td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1.
All fields provided must be filled in.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2.
Please fill in the fields accurately as important details are vital
to access functions such as ticket reservations.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3.
Please use your email address as user id to login </font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4.
Password must be between 6-12 characters and is case sensitive.</font></td>
</tr>
<tr>
<td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
<table width="100%" border="0">
<tr>
<td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
<td width="4%"> </td>
<td width="71%"> </td>
</tr>
<tr>
<td height="29"><font face="Arial">Email Address</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="email" type="text">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass1" type="password" maxlength="20">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Confirm Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass2" type="password" id="password6" maxlength="20">
</font></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td><font face="Arial"><strong>Member Details</strong></font></td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td height="30"><font face="Arial">Full Name</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="name" type="text" size="40">
</font></td>
</tr>
<tr>
<td height="26"><font face="Arial">Telephone Number</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="tel" type="text" size="20" maxlength="10">
(Example: 0123334444, 0323459744)</font></td>
</tr>
<tr>
<td height="24"><font face="Arial">Address</font></td>
<td width="4%"> </td>
<td><label>
<textarea name="address" rows="3"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td><input type="submit" name="submit" value="Submit" onClick="formSubmit()">
<input name="reset" type="reset" id="Reset2" value="Reset">
</td>
</tr>
</table>
<label></label>
</form></td>
</tr>
<tr>
<td height="37">
<div align="center"></div>
</td>
</tr>
</table>
</body>
</html>
devil_vin
09-08-2007, 04:20 PM
Thanks...my screen can remain in signup page.However,why data still insert into database for twice?
<?php
//ini_set("include_path", "path/to/language/file");
include ('dbconn.cfg');
//global variable
$tbl_name = "member";
//$table2 = "registered_member";
//Random confirmation code
//$confirm_code = md5(uniqid(rand()));
//This code runs if the form has been submitted
if (isset($_POST['submit']))
{
// checks if the email address is alredy registered
//if (!get_magic_quotes_gpc())
//{
//$_POST['email'] = addslashes($_POST['email']);
//}
$emailcheck = $_POST['email'];
$check = mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0)
{
?>
<script type="text/javascript">
alert("The email address <?php echo $_POST['email']; ?> is already registered.");
history.back();
</script>
<?php
//die("The email address '" . $_POST['email'] ."' is already registered");
//print '<script type="text/javascript">';
//print 'alert("The email address ' . $_POST['email'] .' is already registered")';
//print '</script>';
}
// encrypt the password
$pass1 = md5($pass1);
//if (!get_magic_quotes_gpc())
//{[]
//pass1 = addslashes($pass1);
//$_POST['member_id'] = addslashes($_POST['member_id']);
//Insert record to database
$insert = mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
VALUES ('" . $_POST['name'] . "','" . $_POST['email'] .
"', '" . $_POST['pass1'] . "','" . $_POST['tel'] . "','" . $_POST['address'] .
"')") or die(mysql_error());
// }
//if successfully inserted,send confirmation link to email
if ($insert)
{
//echo "Thank for your registration!";
//header("Location: http://localhost/www/index.php?frame=thankyou");
$redirectUrl = "http://localhost/www/index.php?frame=thankyou";
print "<script type=\"text/javascript\">";
print "window.location.href = '$redirectUrl'";
print "</script>";
/*
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "admin";// SMTP username
$mail->Password = "itc309";// SMTP password
//$mail->SetLanguage("en","phpmailer/language");
//compose mail
$mail->From = "admin@localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin@localhost.com", "cinema admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
//if not found
else
{
echo "Not found your email in our database";
}
if your email successfully sent
if ($sentmail)
{
echo "Your confirmation link has been sent to your email address.";
}*/
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>New User Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function formSubmit()
{
window.event.returnValue = false;
if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) |
(!form1.address.value)){alert("You did not complete all of the required fields");}
else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12)
{alert("Password must be within 6-20 characters!");form1.pass1.focus()}
else if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();}
else window.event.returnValue = true;
}
</script>
</head>
<body bgcolor="#000000">
<div align="center"></div>
<table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
<tr>
<td width="2%" rowspan="4"> </td>
<td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
</tr>
<tr>
<td height="315" bgcolor="#CCCCFF">
<div align="left">
<table width="100%" border="0">
<tr>
<td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member
Registration</font></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
<tr>
<td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important
Notice:</strong></em></font> </td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1.
All fields provided must be filled in.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2.
Please fill in the fields accurately as important details are vital
to access functions such as ticket reservations.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3.
Please use your email address as user id to login </font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4.
Password must be between 6-12 characters and is case sensitive.</font></td>
</tr>
<tr>
<td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
<table width="100%" border="0">
<tr>
<td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
<td width="4%"> </td>
<td width="71%"> </td>
</tr>
<tr>
<td height="29"><font face="Arial">Email Address</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="email" type="text">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass1" type="password" maxlength="20">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Confirm Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass2" type="password" id="password6" maxlength="20">
</font></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td><font face="Arial"><strong>Member Details</strong></font></td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td height="30"><font face="Arial">Full Name</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="name" type="text" size="40">
</font></td>
</tr>
<tr>
<td height="26"><font face="Arial">Telephone Number</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="tel" type="text" size="20" maxlength="10">
(Example: 0123334444, 0323459744)</font></td>
</tr>
<tr>
<td height="24"><font face="Arial">Address</font></td>
<td width="4%"> </td>
<td><label>
<textarea name="address" rows="3"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td><input type="submit" name="submit" value="Submit" onClick="formSubmit()">
<input name="reset" type="reset" id="Reset2" value="Reset">
</td>
</tr>
</table>
<label></label>
</form></td>
</tr>
<tr>
<td height="37">
<div align="center"></div>
</td>
</tr>
</table>
</body>
</html>
Anybody know what went wrong in this code? The data still insert to database for twice even email address is same...Thanks...
tech_support
09-09-2007, 03:08 AM
Yup. 'Cause the PHP code runs first, then the JS.
Try this:
// checks if the email address is alredy registered
//if (!get_magic_quotes_gpc())
//{
//$_POST['email'] = addslashes($_POST['email']);
//}
$emailcheck = $_POST['email'];
$check = mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0)
{
?>
<script type="text/javascript">
alert("The email address <?php echo $_POST['email']; ?> is already registered.");
history.back();
</script>
<?php
//THIS CODE IS UNCOMMENTED
//So that people without JS can still see the message.
die("The email address '" . $_POST['email'] ."' is already registered");
//END
//print '<script type="text/javascript">';
//print 'alert("The email address ' . $_POST['email'] .' is already registered")';
//print '</script>';
}
// encrypt the password
$pass1 = md5($pass1);
//if (!get_magic_quotes_gpc())
//{[]
//pass1 = addslashes($pass1);
//$_POST['member_id'] = addslashes($_POST['member_id']);
//Insert record to database
$insert = mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
VALUES ('" . $_POST['name'] . "','" . $_POST['email'] .
"', '" . $_POST['pass1'] . "','" . $_POST['tel'] . "','" . $_POST['address'] .
"')") or die(mysql_error());
// }
//if successfully inserted,send confirmation link to email
if ($insert)
{
//echo "Thank for your registration!";
//header("Location: http://localhost/www/index.php?frame=thankyou");
$redirectUrl = "http://localhost/www/index.php?frame=thankyou";
print "<script type=\"text/javascript\">";
print "window.location.href = '$redirectUrl'";
print "</script>";
/*
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "admin";// SMTP username
$mail->Password = "itc309";// SMTP password
//$mail->SetLanguage("en","phpmailer/language");
//compose mail
$mail->From = "admin@localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin@localhost.com", "cinema admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
//if not found
else
{
echo "Not found your email in our database";
}
if your email successfully sent
if ($sentmail)
{
echo "Your confirmation link has been sent to your email address.";
}*/
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>New User Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function formSubmit()
{
window.event.returnValue = false;
if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) |
(!form1.address.value)){alert("You did not complete all of the required fields");}
else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12)
{alert("Password must be within 6-20 characters!");form1.pass1.focus()}
else if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();}
else window.event.returnValue = true;
}
</script>
</head>
<body bgcolor="#000000">
<div align="center"></div>
<table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
<tr>
<td width="2%" rowspan="4"> </td>
<td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
</tr>
<tr>
<td height="315" bgcolor="#CCCCFF">
<div align="left">
<table width="100%" border="0">
<tr>
<td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member
Registration</font></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
<tr>
<td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important
Notice:</strong></em></font> </td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1.
All fields provided must be filled in.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2.
Please fill in the fields accurately as important details are vital
to access functions such as ticket reservations.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3.
Please use your email address as user id to login </font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4.
Password must be between 6-12 characters and is case sensitive.</font></td>
</tr>
<tr>
<td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
<table width="100%" border="0">
<tr>
<td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
<td width="4%"> </td>
<td width="71%"> </td>
</tr>
<tr>
<td height="29"><font face="Arial">Email Address</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="email" type="text">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass1" type="password" maxlength="20">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Confirm Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass2" type="password" id="password6" maxlength="20">
</font></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td><font face="Arial"><strong>Member Details</strong></font></td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td height="30"><font face="Arial">Full Name</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="name" type="text" size="40">
</font></td>
</tr>
<tr>
<td height="26"><font face="Arial">Telephone Number</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="tel" type="text" size="20" maxlength="10">
(Example: 0123334444, 0323459744)</font></td>
</tr>
<tr>
<td height="24"><font face="Arial">Address</font></td>
<td width="4%"> </td>
<td><label>
<textarea name="address" rows="3"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td><input type="submit" name="submit" value="Submit" onClick="formSubmit()">
<input name="reset" type="reset" id="Reset2" value="Reset">
</td>
</tr>
</table>
<label></label>
</form></td>
</tr>
<tr>
<td height="37">
<div align="center"></div>
</td>
</tr>
</table>
</body>
</html>
devil_vin
09-09-2007, 07:57 AM
Wow..Problem fixed.Thanks a lot..:)
Yup. 'Cause the PHP code runs first, then the JS.
Try this:
// checks if the email address is alredy registered
//if (!get_magic_quotes_gpc())
//{
//$_POST['email'] = addslashes($_POST['email']);
//}
$emailcheck = $_POST['email'];
$check = mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0)
{
?>
<script type="text/javascript">
alert("The email address <?php echo $_POST['email']; ?> is already registered.");
history.back();
</script>
<?php
//THIS CODE IS UNCOMMENTED
//So that people without JS can still see the message.
die("The email address '" . $_POST['email'] ."' is already registered");
//END
//print '<script type="text/javascript">';
//print 'alert("The email address ' . $_POST['email'] .' is already registered")';
//print '</script>';
}
// encrypt the password
$pass1 = md5($pass1);
//if (!get_magic_quotes_gpc())
//{[]
//pass1 = addslashes($pass1);
//$_POST['member_id'] = addslashes($_POST['member_id']);
//Insert record to database
$insert = mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
VALUES ('" . $_POST['name'] . "','" . $_POST['email'] .
"', '" . $_POST['pass1'] . "','" . $_POST['tel'] . "','" . $_POST['address'] .
"')") or die(mysql_error());
// }
//if successfully inserted,send confirmation link to email
if ($insert)
{
//echo "Thank for your registration!";
//header("Location: http://localhost/www/index.php?frame=thankyou");
$redirectUrl = "http://localhost/www/index.php?frame=thankyou";
print "<script type=\"text/javascript\">";
print "window.location.href = '$redirectUrl'";
print "</script>";
/*
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "admin";// SMTP username
$mail->Password = "itc309";// SMTP password
//$mail->SetLanguage("en","phpmailer/language");
//compose mail
$mail->From = "admin@localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin@localhost.com", "cinema admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
//if not found
else
{
echo "Not found your email in our database";
}
if your email successfully sent
if ($sentmail)
{
echo "Your confirmation link has been sent to your email address.";
}*/
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>New User Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function formSubmit()
{
window.event.returnValue = false;
if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) |
(!form1.address.value)){alert("You did not complete all of the required fields");}
else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12)
{alert("Password must be within 6-20 characters!");form1.pass1.focus()}
else if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();}
else window.event.returnValue = true;
}
</script>
</head>
<body bgcolor="#000000">
<div align="center"></div>
<table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
<tr>
<td width="2%" rowspan="4"> </td>
<td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
</tr>
<tr>
<td height="315" bgcolor="#CCCCFF">
<div align="left">
<table width="100%" border="0">
<tr>
<td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member
Registration</font></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
<tr>
<td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important
Notice:</strong></em></font> </td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1.
All fields provided must be filled in.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2.
Please fill in the fields accurately as important details are vital
to access functions such as ticket reservations.</font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3.
Please use your email address as user id to login </font></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4.
Password must be between 6-12 characters and is case sensitive.</font></td>
</tr>
<tr>
<td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
<table width="100%" border="0">
<tr>
<td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
<td width="4%"> </td>
<td width="71%"> </td>
</tr>
<tr>
<td height="29"><font face="Arial">Email Address</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="email" type="text">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass1" type="password" maxlength="20">
</font></td>
</tr>
<tr>
<td height="27"><font face="Arial">Confirm Password</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="pass2" type="password" id="password6" maxlength="20">
</font></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td><font face="Arial"><strong>Member Details</strong></font></td>
<td width="4%"> </td>
<td> </td>
</tr>
<tr>
<td height="30"><font face="Arial">Full Name</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="name" type="text" size="40">
</font></td>
</tr>
<tr>
<td height="26"><font face="Arial">Telephone Number</font></td>
<td width="4%"> </td>
<td><font face="Arial">
<input name="tel" type="text" size="20" maxlength="10">
(Example: 0123334444, 0323459744)</font></td>
</tr>
<tr>
<td height="24"><font face="Arial">Address</font></td>
<td width="4%"> </td>
<td><label>
<textarea name="address" rows="3"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td> </tr>
<tr>
<td> </td>
<td width="4%"> </td>
<td><input type="submit" name="submit" value="Submit" onClick="formSubmit()">
<input name="reset" type="reset" id="Reset2" value="Reset">
</td>
</tr>
</table>
<label></label>
</form></td>
</tr>
<tr>
<td height="37">
<div align="center"></div>
</td>
</tr>
</table>
</body>
</html>
asimsddq5
07-06-2014, 10:47 PM
<html>
<head>
<script>
function retrieve()
{
<?php
$con=mysql_connect('localhost','root','');
mysql_select_db('order');
$ins="INSERT INTO `shirts`(`Name`,`price`,`value`,`total`) VALUES ('$name','$price','$value','$total')";
$exc=mysql_query($ins);
if($exc>0)
{
echo '<script type="text/javascript">alert("hello!");</script>';
}
else
{
echo '<script type="text/javascript">alert("bye!");</script>';
}
mysql_close($con);
?>
}
</script>
<link rel="stylesheet" type="text/css" href="css/main.css"/>
</head>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.