Jump to content

Help with SCRIPT


quickfire84

Recommended Posts

Ok, i figured out how to post data in my DB and email it to me and submitter it works, but i get a error..

 

also some of the stuff like phone, anythingelse and idealcustomer does not submit... ??

 

<?php
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$companyname = $_POST['companyname'];
$idealcustomer = $_POST['idealcustomer'];
$productservices = $_POST['productservices'];
$maincompet = $_POST['maincompet'];
$differcompet = $_POST['differcompet'];
$needdone = $_POST['needdone'];
$lookingfor = $_POST['lookingfor'];
$doneby = $_POST['doneby'];
$anythingelse = $_POST['anythingelse'];


// Validation 
if($name == '')  
{ 
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Name</font></p>"); 
} 


if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email)) 
{ 
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>"); 
} 

if($companyname == '')  
{ 
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Company name</font></p>"); 
} 



//MySQL DATA INSERT TAGS START HERE
$con = mysql_connect("localhost","moppiei1_chris1","zxcv2470"); //Replace with your actual MySQL DB Username and Password
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("moppiei1_customers", $con); //Replace with your MySQL DB Name

$name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($_POST['email']);//This value has to be the same as in the HTML form file
$phone=mysql_real_escape_string($_POST['phone']);
$companyname=mysql_real_escape_string($_POST['companyname']);
$idealcustomer=mysql_real_escape_string($_POST['idealcustomer']);
$productservices=mysql_real_escape_string($_POST['productservices']);
$maincompet=mysql_real_escape_string($_POST['maincompet']);
$differcompet=mysql_real_escape_string($_POST['differcompet']);
$needdone=mysql_real_escape_string($_POST['needdone']);
$lookingfor=mysql_real_escape_string($_POST['lookingfor']);
$doneby=mysql_real_escape_string($_POST['doneby']);
$anythingelse=mysql_real_escape_string($_POST['anythingelse']);

$sql="INSERT INTO quote (name,email,phone,companyname,idealcustomer,productservices,maincompet,differcompet,needdone,lookingfor,doneby,anythingelse) VALUES ('$name','$email','$phone','$companyname','$idealcustomer','$productservices','$maincompet','$differcompet','$needdone','$lookingfor','$doneby','$anythignelse')"; /*form_data is the name of the MySQL table where the form data will be saved.*/


if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error()); 
} 
echo "The form data was successfully added to your database."; 
mysql_close($con);
//MySQL DATA INSERT TAGS END HERE




// Build the email (replace the address in the $to section with your own)
$to = 'webmaster@moppieillusions.com';
$subject = "Quote Submittion";
$message = "Name: $name, \n Email: $email, \n Phone Number: $phone, \n Comapny Name: $companyname, \n Ideal Customer: $idealcustomer, \n Product or Services: $productservices, \n Main Competition: $maincompet, \n How You Differ From Competition: $differcompet, \n Services Needed: $needdone, \n Looking For: $lookingfor, \n Need Done By: $doneby, \n Anything Else: $anythingelse";
$headers = "From: $email";

// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);

//Sending auto respond Email to visitor 
$header = "From: webmaster@moppieillusions.com" 
. "Reply-To: webmaster@moppieillusions.com"; 
$subject = "Confirmation of quote enquiry to moppie.illusions"; 
$to = "$email"; 
$message = "Thank You $n for choosing moppie.illusions, Your quote enquiry will be processed immediately \n \n \n Sincerely, \n Chris Cardarello \n Webmaster \n moppie.illusions "; 

// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);

// Redirect
header("Location: success.html");



?>

 

 

How can i get it to still goto my redirect also

 

 

this is error i get

 

The form data was successfully added to your database.

Warning: Cannot modify header information - headers already sent by (output started at /home/moppiei1/public  something about line 90..

Link to comment
Share on other sites

The form data was successfully added to your database.

Warning: Cannot modify header information - headers already sent by (output started at /home/moppiei1/public  something about line 90..

 

you cannot echo anything before a header() function

 

 

as for information missing, check that "name" on the inputs in your form match up with the name in the "POST" array for the ones that are missing.

 

Link to comment
Share on other sites

Ok now with php how would i pull data from several tables by the ID.  main table has a ID set primary key all other tables have the cutomerID as foreign keys set to the ID, so if i wanted to pull data from every table by the ID how would i do so using php???

Link to comment
Share on other sites

Ok now with php how would i pull data from several tables by the ID.  main table has a ID set primary key all other tables have the cutomerID as foreign keys set to the ID, so if i wanted to pull data from every table by the ID how would i do so using php???

 

You'd be looking to use a join. I'd suggest checking out this excellent tutorial: http://www.phpfreaks.com/tutorial/data-joins-unions

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.