I am trying to do an assignment for school. We are using a book that has a bunch of misprints in it. I think my problem is in my page that registers the name and email and password. Could someone please look at it for me? When I run my program I get the error “You must enter a valid email address” so I am sure that the mistake has to be from that point up. Here is my code. Thank you
[php]
<?php $Body = ""; $errors = 0; $email = ""; if (empty($_POST['email'])) { ++$errors; $Body .= "You need to enter an e-mail address.
\n"; $email = ""; } else { $email = stripslashes($_POST['email']); if (preg_match("/^[\w-]+(\.[\w-]+)*@" . "[\w-]+(\.[\w-]+)*(\.[a-zA-Z]{2, })$/i", $email) == 0) { ++$errors; $Body .= "You need to enter a valid " . "e-mail address.
\n"; $email = ""; } } if (empty($_POST['password'])) { ++$errors; $Body .= "You need to enter a password.
\n"; $password = ""; } else $password = stripslashes($_POST['password']); if (empty($_POST['password2'])) { ++$errors; $Body .= "You need to enter a confirmation password.
\n"; $password2 = " "; } else $password2 = stripslashes($_POST['password2']); if ((!(empty($password))) && (!(empty($password2)))) { if (strlen($password) < 6) { ++$errors; $Body .= "The password is too short.
\n"; $password = ""; $password2 = ""; } if ($password <> $password2) { ++$errors; $Body .= "The passwords do not match.
\n"; $password = ""; $password2 = ""; } } if ($errors == 0) { $DBConnect = @mysql_connect("localhost", "root"); if ($DBConnect === FALSE) { $Body .= "Unable to connect to the database server. " . "Error code " . mysql_errno() . ": " . mysql_error() . "
\n"; ++$errors; } else { $DBName = "internships"; $result = @mysql_select_db($DBName, $DBConnect); if ($result === FALSE) { $Body .= "Unable to select the database. " . "Error code " . mysql_ errno($DBConnect) . ": " . mysql_error($DBConnect) . "
\n"; ++$errors; } } } $TableName = "interns"; if ($errors == 0) { $SQLstring = "SELECT count(*) FROM $TableName" . "where email=$email"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult !== FALSE) { $Row = mysql_fetch_row($QueryResult); if ($Row[0]>0) { $Body .= "The email address entered (" . htmlentities($email) . ") is already registered.
\n"; ++$errors; } } } if ($errors > 0) { $Body .= "Please use your browser's BACK button to return" . " to the form and fix the errors indicated.
\n"; } if ($errors == 0) { $first = stripslashes($_POST['first']); $last = stripslashes($_POST['last']); $SQLstring = "INSERT INTO $TableName " . " (first, last, email, password_md5) " . " VALUES( '$first', '$last', '$email', " . " '" . md5($password) . "')"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) { $Body .= "Unable to save your registration " . " information. Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
\n"; ++$errors; } else { $InternID = mysql_insert_id($DBConnect); } setcookie("internID", $InternID); mysql_close($DBConnect); } if ($errors == 0) { $InternName = $first . " " . $last; $Body .= "Thank you, $InternName. "; $Body .= "Your new Intern ID is " . $InternID . ".
\n"; } ?> Intern Registration