Simple Forms with php
Moderator: General Moderators
Simple Forms with php
Hello,
I am trying to get a simple form to work on my website. I used the tutorial off of phpfreaks to create a form. I can see the form on my website, and I have the backend php to perform the POST method, but when I fill out the form, the page goes blank and nothing happens. Where am I supposed to place the form and the .php to get it to work?
Talk to me like I am a 1st grader, I am pretty new at this.
Thanks to anyone for your help.
http://www.ameechapman.com to check out the form (go to contact)
I will change it to suit me as soon as it is working...
I am trying to get a simple form to work on my website. I used the tutorial off of phpfreaks to create a form. I can see the form on my website, and I have the backend php to perform the POST method, but when I fill out the form, the page goes blank and nothing happens. Where am I supposed to place the form and the .php to get it to work?
Talk to me like I am a 1st grader, I am pretty new at this.
Thanks to anyone for your help.
http://www.ameechapman.com to check out the form (go to contact)
I will change it to suit me as soon as it is working...
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
Ok, here is the php called contact.php
THANKS!
<html>
<head>
</head>
<body>
<?php
/* grabs the POST variables and puts them into variables that we can use */
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$website=$_POST['website'];
$countryCode=$_POST['countryCode'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$zipCode=$_POST['zipCode'];
$heardAbout=$_POST['heardAbout'];
$inquiring=$_POST['inquiring'];
//---------VALIDATION-------->
if($firstName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
}
if($lastName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your last name<br>\n";//----> ERROR if no input
}
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail address<br>\n";//----> ERROR if no input
}
if($phone){//----> CHECK input
}
else{
$error.="Please, go back and fill out your phone number<br>\n";//----> ERROR if no input
}
if($address){//----> CHECK input
}
else{
$error.="Please, go back and fill out your mailing address<br>\n";//----> ERROR if no input
}
if($city){//----> CHECK input
}
else{
$error.="Please, go back and fill out your city name<br>\n";//----> ERROR if no input
}
if($zipCode){//----> CHECK input
}
else{
$error.="Please, go back and fill out your zip code<br>\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost
immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Fax: ".$fax."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
."Where did you hear about us? ".$heardAbout."\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
$toAddress="ameechapmanband@hotmail.com"; /* change this! */
$subject="Website Contact"; /* change this! */
$recipientSubject="Amee Chapman's Contact Form"; /* change this! */
$receiptMessage = "Thank you ".$firstName." for inquiring about Amee Chapman!\n\n\nHere is what you submitted to
us:\n\n"
."--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Fax: ".$fax."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
."Where did you hear about us? ".$heardAbout."\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;
//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("www.hyberia.net","amee", "chapman") or die("Unable to connect!"); /* change this! */
mysql_select_db("generalContact.sql") or die("Unable to select database!"); /* change this! */
// EXECUTE QUERY --->
$query="INSERT INTO generalContact (
firstName,
lastName,
company,
email,
website,
countryCode,
phone,
phoneExt,
mobile,
fax,
address,
city,
state,
country,
zipCode,
heardAbout,
inquiringOn)
VALUES(
'".$firstName."',
'".$lastName."',
'".$company."',
'".$email."',
'".$website."',
'".$countryCode."',
'".$phone."',
'".$phoneExt."',
'".$mobile."',
'".$fax."',
'".$address."',
'".$city."',
'".$state."',
'".$country."',
'".$zipCode."',
'".$heardAbout."',
'".$inquiring."')";
//////----->
$result=mysql_query($query) or die("Error in query:".mysql_error());
//if ($result)
//echo mysql_affected_rows()." row inserted into the database effectively.";
// CLOSE CONNECTION --->
mysql_close($connection);
///////////////////////////////////////////////////////////////////////////////////
}
else{
print "Sorry, but the form cannot be sent until the fields indicated are filled out completely -
<br>\n";
print "$error<br>\n";
print "<br>\n";
print "<br>\n";
print "Please use your \"Back\" button to return to the form to correct the omissions. Thank
you.<br>\n";
}
?>
</body>
</html>
THANKS!
<html>
<head>
</head>
<body>
<?php
/* grabs the POST variables and puts them into variables that we can use */
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$website=$_POST['website'];
$countryCode=$_POST['countryCode'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$zipCode=$_POST['zipCode'];
$heardAbout=$_POST['heardAbout'];
$inquiring=$_POST['inquiring'];
//---------VALIDATION-------->
if($firstName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
}
if($lastName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your last name<br>\n";//----> ERROR if no input
}
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail address<br>\n";//----> ERROR if no input
}
if($phone){//----> CHECK input
}
else{
$error.="Please, go back and fill out your phone number<br>\n";//----> ERROR if no input
}
if($address){//----> CHECK input
}
else{
$error.="Please, go back and fill out your mailing address<br>\n";//----> ERROR if no input
}
if($city){//----> CHECK input
}
else{
$error.="Please, go back and fill out your city name<br>\n";//----> ERROR if no input
}
if($zipCode){//----> CHECK input
}
else{
$error.="Please, go back and fill out your zip code<br>\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost
immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Fax: ".$fax."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
."Where did you hear about us? ".$heardAbout."\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
$toAddress="ameechapmanband@hotmail.com"; /* change this! */
$subject="Website Contact"; /* change this! */
$recipientSubject="Amee Chapman's Contact Form"; /* change this! */
$receiptMessage = "Thank you ".$firstName." for inquiring about Amee Chapman!\n\n\nHere is what you submitted to
us:\n\n"
."--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Fax: ".$fax."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
."Where did you hear about us? ".$heardAbout."\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;
//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("www.hyberia.net","amee", "chapman") or die("Unable to connect!"); /* change this! */
mysql_select_db("generalContact.sql") or die("Unable to select database!"); /* change this! */
// EXECUTE QUERY --->
$query="INSERT INTO generalContact (
firstName,
lastName,
company,
email,
website,
countryCode,
phone,
phoneExt,
mobile,
fax,
address,
city,
state,
country,
zipCode,
heardAbout,
inquiringOn)
VALUES(
'".$firstName."',
'".$lastName."',
'".$company."',
'".$email."',
'".$website."',
'".$countryCode."',
'".$phone."',
'".$phoneExt."',
'".$mobile."',
'".$fax."',
'".$address."',
'".$city."',
'".$state."',
'".$country."',
'".$zipCode."',
'".$heardAbout."',
'".$inquiring."')";
//////----->
$result=mysql_query($query) or die("Error in query:".mysql_error());
//if ($result)
//echo mysql_affected_rows()." row inserted into the database effectively.";
// CLOSE CONNECTION --->
mysql_close($connection);
///////////////////////////////////////////////////////////////////////////////////
}
else{
print "Sorry, but the form cannot be sent until the fields indicated are filled out completely -
<br>\n";
print "$error<br>\n";
print "<br>\n";
print "<br>\n";
print "Please use your \"Back\" button to return to the form to correct the omissions. Thank
you.<br>\n";
}
?>
</body>
</html>
No changes, just making it more readable:
Code: Select all
<html>
<head>
</head>
<body>
<?php
/* grabs the POST variables and puts them into variables that we can use */
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$website=$_POST['website'];
$countryCode=$_POST['countryCode'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$zipCode=$_POST['zipCode'];
$heardAbout=$_POST['heardAbout'];
$inquiring=$_POST['inquiring'];
//---------VALIDATION-------->
if($firstName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
}
if($lastName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your last name<br>\n";//----> ERROR if no input
}
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail address<br>\n";//----> ERROR if no input
}
if($phone){//----> CHECK input
}
else{
$error.="Please, go back and fill out your phone number<br>\n";//----> ERROR if no input
}
if($address){//----> CHECK input
}
else{
$error.="Please, go back and fill out your mailing address<br>\n";//----> ERROR if no input
}
if($city){//----> CHECK input
}
else{
$error.="Please, go back and fill out your city name<br>\n";//----> ERROR if no input
}
if($zipCode){//----> CHECK input
}
else{
$error.="Please, go back and fill out your zip code<br>\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost
immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Fax: ".$fax."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
."Where did you hear about us? ".$heardAbout."\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
$toAddress="ameechapmanband@hotmail.com"; /* change this! */
$subject="Website Contact"; /* change this! */
$recipientSubject="Amee Chapman's Contact Form"; /* change this! */
$receiptMessage = "Thank you ".$firstName." for inquiring about Amee Chapman!\n\n\nHere is what you submitted to
us:\n\n"
."--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Fax: ".$fax."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
."Where did you hear about us? ".$heardAbout."\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;
//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("www.hyberia.net","amee", "chapman") or die("Unable to connect!"); /* change this! */
mysql_select_db("generalContact.sql") or die("Unable to select database!"); /* change this! */
// EXECUTE QUERY --->
$query="INSERT INTO generalContact (
firstName,
lastName,
company,
email,
website,
countryCode,
phone,
phoneExt,
mobile,
fax,
address,
city,
state,
country,
zipCode,
heardAbout,
inquiringOn)
VALUES(
'".$firstName."',
'".$lastName."',
'".$company."',
'".$email."',
'".$website."',
'".$countryCode."',
'".$phone."',
'".$phoneExt."',
'".$mobile."',
'".$fax."',
'".$address."',
'".$city."',
'".$state."',
'".$country."',
'".$zipCode."',
'".$heardAbout."',
'".$inquiring."')";
//////----->
$result=mysql_query($query) or die("Error in query:".mysql_error());
//if ($result)
//echo mysql_affected_rows()." row inserted into the database effectively.";
// CLOSE CONNECTION --->
mysql_close($connection);
///////////////////////////////////////////////////////////////////////////////////
}
else{
print "Sorry, but the form cannot be sent until the fields indicated are filled out completely -
<br>\n";
print "$error<br>\n";
print "<br>\n";
print "<br>\n";
print "Please use your "Back" button to return to the form to correct the omissions. Thank
you.<br>\n";
}
?>
</body>
</html>-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
try changing
to
that may/not work, but its worth a try
Code: Select all
if($error==""){Code: Select all
if(!$error){I'd start adding some debug echo's.
For example, make the first lines of contact.php like this (even before the html bit)
<?php
echo 'Debug 1<br />';
?>
Then start adding similar lines at various points further down the script, changing the Debug number everytime, 1..2..3 etc..
Then at least you should see how far the script is getting before it dies and see if you can pin down the exact line where it's happening.
For example, make the first lines of contact.php like this (even before the html bit)
<?php
echo 'Debug 1<br />';
?>
Then start adding similar lines at various points further down the script, changing the Debug number everytime, 1..2..3 etc..
Then at least you should see how far the script is getting before it dies and see if you can pin down the exact line where it's happening.
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
Code: Select all
<?php
echo "Debug 1<br />";
?>
<html>
<head>
</head>
<body>
<?php
/* grabs the POST variables and puts them into variables that we can use */
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$website=$_POST['website'];
$countryCode=$_POST['countryCode'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$zipCode=$_POST['zipCode'];
$heardAbout=$_POST['heardAbout'];
$inquiring=$_POST['inquiring'];
//---------VALIDATION-------->
if($firstName){//----> CHECK input
echo "Debug 2<br />";
}
else{
$error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
}
if($lastName){//----> CHECK input
echo "Debug 3<br />";
}
else{
$error.="Please, go back and fill out your last name<br>\n";//----> ERROR if no input
}
if($email){//----> CHECK input
echo "Debug 4<br />";}
else{
$error.="Please, go back and fill out your e-mail address<br>\n";//----> ERROR if no input
}
if($phone){//----> CHECK input
echo "Debug 5<br />";}
else{
$error.="Please, go back and fill out your phone number<br>\n";//----> ERROR if no input
}
if($address){//----> CHECK input
echo "Debug 6<br />";}
else{
$error.="Please, go back and fill out your mailing address<br>\n";//----> ERROR if no input
}
if($city){//----> CHECK input
echo "Debug 7<br />";}
else{
$error.="Please, go back and fill out your city name<br>\n";//----> ERROR if no input
}
if($zipCode){//----> CHECK input
echo "Debug 8<br />";}
else{
$error.="Please, go back and fill out your zip code<br>\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if(!$error){
echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost
immediately.";Well, if that's the code that you can currently view by going to http://www.ameechapman.com/contact.php then something else is wrong as it's not even 'doing' the first debug echo.
Does a simple page, let's call it test.php with only the following code work on the server ok?
If so, can you provide a link to test.php so we can see it?
Does a simple page, let's call it test.php with only the following code work on the server ok?
Code: Select all
<?php phpinfo() ?>