Hello. I have some php that is reading to a sql database that contains our subscribers information. What I need it to do is read the field "last" and then if their name is not in the data, then I need it display an error code. If it matches, than it will display their registration information to confirm it is correct.
Below is what I have already. Thanks
<?php
// Set the database access information as constants.
define('DB_USER', '****');
define ('DB_PASSWORD', '****');
define ('DB_HOST', '****');
define ('DB_NAME', '****');
// Make the connnection and then select the database.
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD); //or die ("Could not connect to DB");
mysql_select_db (DB_NAME); //or die ("Could not find DB");
// Select all rows with last name
$query = "SELECT * FROM **** WHERE last='$last'";
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
//check results
while($row = mysql_fetch_array($result)){
$match = $match+1;
}
if($error >= "1"){
echo"<table width='700'><tr><td><br><br><br>The information you have provided does not match our database of CBC Magazine paid subscribers.<br><br>If you paid to receive the CBC® Magazine regularly and should be in our database, please call Holly at 216.831.9557 or email her at ****, and she will process your $35 registration manually.<br><br>If you did not pay to receive the magazine, you can click back to continue your registration for Amplify at the $45 non-subscriber rate.<br><br>If your event registration is not processed and confirmed within 48 hours, A CDG representative will contact you. Thank you.</td></tr></table>";
}
mysql_close($dbc);
$con = mysql_connect("****","****","****"); //Replace with your actual MySQL DB Username and Password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("****", $con); //Replace with your MySQL DB Name
$first=mysql_real_escape_string($_POST['first']); //This value has to be the same as in the HTML form file
$last=mysql_real_escape_string($_POST['last']); //This value has to be the same as in the HTML form file
$company=mysql_real_escape_string($_POST['company']);
$address=mysql_real_escape_string($_POST['address']);
$city=mysql_real_escape_string($_POST['city']);
$state=mysql_real_escape_string($_POST['state']);
$zip=mysql_real_escape_string($_POST['zip']);
$email=mysql_real_escape_string($_POST['email']);
$phone=mysql_real_escape_string($_POST['phone']);
$sql="INSERT INTO CCA_Registration_a (first,last,company,address,city,state,zip,email,phone) VALUES ('$first','$last','$company','$address','$city','$state','$zip','$email','$phone')"; /*form_data is the name of the MySQL table where the form data will be saved.
name and email are the respective table fields*/
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
mysql_close($con);
// Configuration Settings Holly gets email
$SendFrom = "Paid Subscriber and CCA Award Registration <****@****.com>";
$SendTo = "****@****.com";
$SubjectLine = "Paid Subscriber and CCA Award Registration";
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
$MsgBody .= "$Field: $Value\n";
$MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");
header("Location: $ThanksURL");
$msg_cbc = "Thank you for your registration to the Connectors' Choice Awards";
{
echo"<table width='535'><tr><td><b>Registration Information:</b></td><td></td></tr>";
echo"<tr><td bgcolor='#EEEEEE'>First Name: </td><td bgcolor='#EEEEEE'>".$first."</td></tr>";
echo"<tr><td>Last Name: </td><td>".$last."</td></tr>";
echo"<tr><td bgcolor='#EEEEEE'>Email: </td><td bgcolor='#EEEEEE'>".$email."</td></tr>";
echo"<tr><td>Company: </td><td>".$company."</td></tr>";
echo"<tr><td bgcolor='#EEEEEE'>Phone: </td><td bgcolor='#EEEEEE'>".$phone."</td></tr>";
echo"<tr><td>Address: </td><td>".$address."</td></tr>";
echo"<tr><td bgcolor='#EEEEEE'>City: </td><td bgcolor='#EEEEEE'>".$city."</td></tr>";
echo"<tr><td>State: </td><td>".$state."</td></tr>";
echo"<tr><td bgcolor='#EEEEEE'>Zip: </td><td bgcolor='#EEEEEE'>".$zip."</td></tr>";
echo"<table width='535'><tr><td> </td><td></td></tr><br/><br/>";
}
//customer gets email
mail($_POST['email'],"Connectors' Choice Awards Registration",$msg_cbc,"FROM: ****@****"); //Send email to them
?>