Jump to content

Echo message after email validation


matt.sisto

Recommended Posts

I have the email validation working now, but I want the form to echo a message if the email address already exists, I have attempted the if statement but it is not working, can anyone point out my mistakes. Appreciate any help.

addconsultant.php:

<?php
  require "dbconn2.php";
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $address_first_line = $_POST['address_first_line'];
  $post_code = $_POST['post_code'];
  $email_address = $_POST['email_address'];  
  $phone_number = $_POST['phone_number'];  
  $y = $_POST['y'];
  $m = $_POST['m'];
  $d = $_POST['d'];
  $rate_id = $_POST['rate'];
  $passwd = $_POST['passwd'];
  $enc = sha1($passwd);
  $dob = $y."-".$m."-".$d." ".$_POST["dob"];
  
  $sql = mysql_query("SELECT * FROM consultant WHERE email_address = '$email_address'");
if (mysql_num_rows($sql) == 0)
  {
  
  $sql = "INSERT INTO consultant VALUES (0,'".$first_name."','".$last_name."','".$address_first_line."','".$post_code."',
									 '".$email_address."','".$phone_number."','".$dob."','".$rate."','".$enc."')";
  $result = mysql_query ($sql, $connection)
    or die ("Couldn't perform query $sql <br />".mysql_error());
  header("Location: addconsultantform.php");
  exit();
  }
  else{
   $error = $_POST['error'];
   header("Location: addconsultantform.php");
  exit();
  }

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Add Consultant</title>

</head>

<body>

</body>
</html>

addconsultantform.php:

<?php
  require "dbconn2.php";
  $error = $_GET['error'];

$sql="SELECT rate_id, rate FROM rate";
  $result=mysql_query($sql);
  $rate_option="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["rate_id"];
    $rate=$row["rate"];
    $rate_option.="<OPTION VALUE=\"$id\">".$rate;
}

if ($error == 1) 
{
echo '<h2>Sorry but an account with this email address already exists</h2>';

}
?>

(I have only included the php, I don't want to bore you with my html, and css.)

 

Thanks and regards. 8)

Link to comment
https://forums.phpfreaks.com/topic/150889-echo-message-after-email-validation/
Share on other sites

$sql = mysql_query("SELECT * FROM consultant WHERE email_address = '$email_address'");

if (mysql_num_rows($sql) == 0)

  {

// This is if the e-mail is not in the database

 

else {

$error=True;

$errormessage="That e-mail is already in the database";

header("Location: addconsultantform.php?error=".$error."&message=".$message);

}

[/code]

then in addconsultantform.php check for the error and message

if(isset($_GET['error']) && $_GET['error']) 
{ 
echo $_GET['error']; 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.