PDA

View Full Version : Need help getting script to work properly


MrTickles
11-24-2002, 01:27 PM
Hello,

I am having a hard time getting the below script to work properly. I need some help if someone could lend me a hand please.

This is what Im trying to get it to do:

There is a join page. I have the user enter a name and an email, then re-enter their email to verify it.
the code for this page is as follows:

<form method='POST' action='join.php'>
<table border='1' width='283' cellspacing='0' cellpadding='5'align='center' bordercolor='#400000'>
<tr>
<td align='right' valign='top'><font color="#ffffff">Name:</td>
<td valign='top'><input type='text' name='name' size='20'></td>
</tr>
<tr>
<td align='right' valign='top'><font color="#ffffff">Email:</td>
<td valign='top'><input type='text' name='email' size='20'>
<input type='hidden' name='save1'></td>
</tr>
<tr>
<td align='right' valign='top'><font color="#ffffff">Verify Email:</td>
<td valign='top'><input type='text' name='emailchk' size='20'></td>
</tr>
<tr>
<td ><center><input type="reset"></td>
<td><center><input type='submit' value='Submit' name='Join'></td>
</table>
</form>

</body>
</html>

The information is passes to a php page.
This where I am having trouble.

I want to validate that the email address they entered is in email address format(xxx@xxx.xxx).
I want the email they entered twice to match.
I want all the boxes on the html page to be filled in.

Right now i have it so it says if the email is valid or not, but if it is invalid it still allows the user to be allowed into the database:(

It wont check to see if both emails are the same.

If someone could help that would be great. I can supply more info if it is needed!! Thank you very much

Heres the join.php code

<?php
include("db.inc.php");
$save1 = $_POST['save1'];
$email =$_POST['email'];
$emailchk =$_POST['emailchk'];
$name =$_POST['name'];
if(IsSet($save1))
{
if($email && $name && $emailchk > NULL)
{
$sql = mysql_num_rows(mysql_query("SELECT `email` FROM `members` WHERE 1 AND `email` = '$email'"));
function valid_email($email) {
if(ereg("^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$",$email)) {
return TRUE;
} else {
return FALSE;
}
}

if (valid_email($email)) {
echo "Email valid!";
} else {
echo "Invalid email!";
}
if(!$sql > 0)
{
$date = date("j/m/Y");
$saveit = "INSERT INTO `members` (name, email, Date) VALUES ('$name', '$email', '$date')";
$savedone = mysql_query($saveit) or die("ERROR while INSERTING new member record.");
print("<b>Thank you for you joining the HighKnightz Clan.<br><a href='javascript:window.history.back()'>Back</a>
");
}
}


else
{
print("This email address is already in use.");
}
}
else
{
Print("<b>Please fill in ALL the fields!<br>");

}

?>

raptori
11-24-2002, 04:39 PM
//use this method to check to see if the user filled everything
if (!$name || !$email || !$emailchk ){
echo "Please fill all the required fileds.<br>\n"
}
else{
//now here you check to see if email is the same
if ($email == $emailchk){
//check to see if the eamil is in the right format
if(ereg("^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$",$email))_{
//do the db stuff here
}
else{
echo "Email is not the same and/or not the right format";
}
}
}



Hope this helps