Hi Guys
I am still new to the php world so forgive me if this is easy, I have a fully functioning contact form which I need a little help with. At the moment it customers fill an enquiry form in which goes to an mysql data base, sends me an email and then autorespondes to there enquiry. what I need it to do is send directly to the branches email. So what I thought about doing is create a table called pit_locations with id, name, branch and email.
this is query I have in serted
$sql = mysql_query("SELECT Email FROM pit_locations WHERE Location ='$postcode' LIMIT 1");
$info = mysql_fetch_array($sql);
but I keep getting this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
here is the script the error is in red on line 167 I would be very grateful for any help
<?php
// Connect to database
$hostname = "0.0.0.0";
$username = "test";
$password = "test";
$dbname = "test";
$usertable = "test";
$f_name = $REQUEST['f_name'];
$postcode = $REQUEST['postcode'];
$tel = $REQUEST['tel'];
$mobile = $REQUEST['mobile'];
$email = $REQUEST['email'];
$course = $REQUEST['course'];
$go = "1";
mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");
$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");
$errmsg = ''; // error message
$f_name = ''; // sender's name
$postcode = ''; // sender's name
$tel = ''; // message tel
$mobile = ''; // message tel
$email = ''; // sender's email addres
$course = ''; // the message itself
if(isset($POST['send']))
{
$f_name = $POST['f_name'];
$postcode = $POST['postcode'];
$tel = $POST['tel'];
$mobile = $POST['mobile'];
$email = $POST['email'];
$course = $_POST['course'];
if(trim($f_name) == '')
{
$errmsg = 'Please enter your name';
}
else if(trim($postcode) == '')
{
$errmsg = 'Please enter your postcode';
}
else if(trim($tel) == '')
{
$errmsg = 'Please enter Your Telephone Number:';
}
else if(trim($mobile) == '')
{
$errmsg = 'Please enter your mobile';
}
else if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
else if(trim($course) == '')
{
$errmsg = 'Please enter the course your interested in';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$tel = stripslashes($tel);
$message = stripslashes($message);
}
$query = "INSERT INTO pitman (id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('', '$f_name', '$postcode', '$tel', '$mobile', '$email' , '$course', NOW())";
$result = mysql_query($query) or DIE("Could not Execute Query on table $usertable");
// the email will be sent here
$to = "email";
$user_message .= "Name: $f_name \r\n";
$user_message .= "postcode: $postcode \r\n";
$user_message .= "tel: $tel \r\n";
$user_message .= "mobile: $mobile \r\n";
$user_message .= "email: $email \r\n";
$user_message .= "course: $course \r\n";
$headers = "- company \r\n";
$headers .= "Reply-To: $email";
$sql = mysql_query("SELECT Email FROM pit_locations WHERE Location ='$postcode' LIMIT 1");
$info = mysql_fetch_array($sql);
mail('email','Company',$user_message,$headers);
$autoreply="Thank you for your enquiry, $f_name.
\n\n$user_message\n\nThis is an automated reply.";
$subject="Thank you for Enquiring $name!
";
mail($email, $subject, $autoreply);
?>
<div align="center" class="boldenquire">Thank you for your enquiry and we look forward to helping you. </div>
<?php
}
}
mysql_close();
if(!isset($_POST['send']) || $errmsg != '')
{
?>