Jump to content

Php Enquiry form Help


ace2721

Recommended Posts

Hi Guys

 

I am still new to the php world so forgive me if I come across as a bit thick, I have a fully functioning contact form which I need a little help with. At the moment it stores contact details in a database as well as sends me an emails and an auto response to the customer, what I am trying to do it make it look a table called pit_locations and send it to the relevant branch as well as sending me a copy, I have put the code into the script now but 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

 

<?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 != '')

{

?>

Link to comment
https://forums.phpfreaks.com/topic/146655-php-enquiry-form-help/
Share on other sites

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.