PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 4th, 2005, 08:33 PM
moggi1964 moggi1964 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 12 moggi1964 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 48 sec
Reputation Power: 0
Back with a vengeance - The sequel to "Told you I would be back"

Well I have spent days trying to resolve this one. I have given up on trying to get the mysql to work, it really isn't important just now.

I bought a couple of php books and read loads of forum (is it forum for plural or perhaps fori but surely not forums!? Fora??).

Anyway, I have got to the point where the form will email me with some data but much of it is missing. So I reintroduced the validation checks and this is what is missing:

"Sorry, but the form cannot be sent until the fields indicated are filled out completely - Please, go back and fill out your first name Please, go back and fill out your house number and street name Please, go back and fill out your city Please, go back and fill out your state Please, go back and fill out your country of reidence Please, go back and fill out your daytime telephone number Please, go back and fill out your evening telephone number Please, go back and fill out the section asking you for one thing to focus on Please use your "Back" button to return to the form to correct the omissions. Thank you"

Now you can guess that I have put entries into those fields so ....help!

Here's the php code:

PHP Code:
/* grabs the POST variables and puts them into variables that we can use */
$Title= [PHP]%4$s 
POST['Title'];
$firstname=
PHP Code:
%4$s 
POST['First Name'];
$PreferredName=
PHP Code:
%4$s 
POST['Preferred Name'];
$surname=
PHP Code:
%4$s 
POST['Surname'];
$Email=
PHP Code:
%4$s 
POST['Email'];
$street=
PHP Code:
%4$s 
POST['Street'];
$ApartmentNo=
PHP Code:
%4$s 
POST['Apartment Number'];
$city=
PHP Code:
%4$s 
POST['City'];
$state=
PHP Code:
%4$s 
POST['State'];
$ZipCode=
PHP Code:
%4$s 
POST['Zipcode'];
$country=
PHP Code:
%4$s 
POST['Country'];
$daytimetel=
PHP Code:
%4$s 
POST['Daytime telephone'];
$cancallday=
PHP Code:
%4$s 
POST['Can call in day'];
$eveningtel=
PHP Code:
%4$s 
POST['Evening telephone'];
$cancallevenin=
PHP Code:
%4$s 
POST['Can call evening'];
$OneThing=
PHP Code:
%4$s 
POST['One Thing'];
PHP Code:
//-------VAILDATION 
if( ! $firstname 

$error.="Please, go back and fill out your first name\n"
};
if( ! 
$surname 

$error.="Please, go back and fill out your surname\n"
};
if( ! 
$Email 

$error.="Please, go back and fill out your email address\n"
};
if( ! 
$street 

$error.="Please, go back and fill out your house number and street name\n"
};
if( ! 
$city 

$error.="Please, go back and fill out your city\n"
};
if( ! 
$state 

$error.="Please, go back and fill out your state\n"
};
if( ! 
$country 

$error.="Please, go back and fill out your country of reidence\n"
};
if( ! 
$daytimetel 

$error.="Please, go back and fill out your daytime telephone number\n"
};
if( ! 
$eveningtel 

$error.="Please, go back and fill out your evening telephone number\n"
}
if( ! 
$OneThing 

$error.="Please, go back and fill out the section asking you for one thing to focus on\n"
};
//-------->ERROR FREE??
if($error==""){
echo 
"Thank you for inquiring about icoachdads.com! A receipt of your submission will be e-mailed to you almost immediately.";
 
//----------------------------------
$mailContent="--------CONTACT--------\n"
."Title: ".$Title."\n"
."First Name: ".$firstName."\n"
."Preferred Name: ".$lPreferedName."\n"
."Surname: ".$surname."\n"
."E-mail: ".$Email."\n\n--------ADDRESS--------\n"
."Street: ".$street."\n"
."Apartment Number: ".$ApartmentNo."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Zipcode: ".$ZipCode."\n"
."Country: ".$couontry."\n"
."Daytime telephone: ".$dattimetel."\n\n--------PHONE--------\n"
."Can call in daytime: ".$cancallday."\n"
."Evening telephone: ".$eveningtel."\n"
."Can call in evening: ".$cancallevenin."\n"
."One thing: ".$OneThing."\n";
//----------------------------------
$toAddress="forms@icoachdads.com";
$subject="icoachdads.com's free coaching session'";
$recipientSubject="icoachdads.com's Contact Form";
$receiptMessage "Thank you ".$firstName." for inquiring about icoachdads.com's free coaching session!\n\n\nHere is what you submitted to me:\n\n";
"--------CONTACT--------\n"
."Title: ".$Title."\n"
."First Name: ".$firstName."\n"
."Preferred Name: ".$PreferedName."\n"
."Surname: ".$surname."\n"
."E-mail: ".$Email."\n\n--------ADDRESS--------\n"
."Street: ".$Street."\n"
."Apartment Number: ".$ApartmentNo."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Zipcode: ".$ZipCode."\n"
."Country: ".$country."\n"
."Daytime telephone: ".$daytimetel."\n\n--------PHONE--------\n"
."Can call in daytime: ".$cancallday."\n"
."Evening telephone: ".$eveningtel."\n"
."Can call in evening: ".$cancallevenin."\n"
."One thing: ".$OneThing."\n";
//----------------------------------
mail($email$subject$receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;
//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("localhost","####""##3") or die("Unable to connect!"); /* change this! */
mysql_select_db("########") or die("Unable to select database!"); /* change this! */
// EXECUTE QUERY --->
$query="INSERT INTO GeneralContact (
Title,
firstname,
preferredname,
surname,
Email,
street,
ApartmentNo,
city,
state,
ZipCode,
country,
daytimetel,
cancallday,
eveningtel,
cancallevenin,
OneThing)
VALUES(
'"
.$Title."',
'"
.$firstName."',
'"
.$preferredname."',
'"
.$surname."',
'"
.$Email."',
'"
.$street."',
'"
.$ApartmentNo."',
'"
.$city."',
'"
.$state."',
'"
.$ZipCode."',
'"
.$country."',
'"
.$daytimetel."',
'"
.$cancallday."',
'"
.$eveningtel."',
'"
.$cancallevenin."',
'"
.$OneThing."')";
//////----->
$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 - \n";
print 
"$error\n";
print 
"\n";
print 
"\n";
print 
"Please use your \"Back\" button to return to the form to correct the omissions. Thank you.\n";



Would it help any if I posted the HTML page?

I have had to put a temporary page in whilst this is fixed which is kinda frustrating.

Thanks all.

Moggi1964

Reply With Quote
  #2  
Old February 5th, 2005, 09:33 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
A couple of things come to mind. One rename some of your variables, e.g.
PHP Code:
 $Title $_POST['Title'];
$firstname $_POST['First Name'];
# You should have some standards for your names, in this case title is capitalised, but first name isn't. 
# There are various standards you can use eg:
# $title, $firstName or
# $title, $first_name
# Just use whatever you like the most, but they key is to keep consistant, 

# Second your POSTed varable names, i would reccomend not having any spaces in the names, 
# eg 'First Name' would become 'firstName' or something, think about capitalisation and keep it consistant as i said before.
# This will need changes to your html form, and the php code. 

When setting your variables, you may want to usee the '?' operator like so:
PHP Code:
 $Title=$_POST['Title'];
# becomes
$title = isSet( $_POST['title'] ) ? $_POST['title'] : '';
#
# this is the short hand way of typing:
if( isSet( $_POST['title'] ) )
{
    
$title $_POST['title'];
}
else
{
    
$title '';
}
# This will explicitly set varable to the entered value or to nothing. 


On a more of an aesthetics note you may wish to include a <br /> tag after each error, this will split the messages up nicer and improve readability. e.g.
PHP Code:
 $error .= "Please, go back and fill out your first name\n"
# becomes
    
$error .= "Please, go back and fill out your first name<br />\n"


You may even want to change it so it reads something like:

"Sorry, but the form cannot be sent until the fields indicated are filled out completely:
first name is required
house number is required
street name is required
city is required
state is required
country of reidence is required
daytime telephone number is required
evening telephone number is required
one thing to focus on is required
Please use your "Back" button to return to the form to correct the omissions.
Thank you"

Just a thought, try out some of these suggestion and let us know how you get on.

p.s. please remember to wrap all php code in the php tags, click on the php button, to the right to the big # sign when posting!
__________________
http://www.phptutorials.cjb.net. go on, give it a click!

Reply With Quote
  #3  
Old February 6th, 2005, 05:05 PM
moggi1964 moggi1964 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 12 moggi1964 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 48 sec
Reputation Power: 0
Thumbs up Sorry abou the php posting

I didn't realise the button next to the #existed and I tried to wrap the text but it didn't work!!

Thanks for your response. I will try it out and see what happens.

The advice you give on tidying up is appreciated too.

Moggi1964

Reply With Quote
  #4  
Old February 6th, 2005, 09:21 PM
moggi1964 moggi1964 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 12 moggi1964 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 48 sec
Reputation Power: 0
Still getting a problem at line 79...Parse error?????

Not quite there it would seem!!

Tried seeing what might be causing the line 79 problem ut nothing obvious.

I'm sure you'll see it!

Moggi



/* grabs the POST variables and puts them into variables that we can use */
PHP Code:
 $title = isSet( 4$s POST['title'] ) ? %4$s POST['title'] : '';
$firstname = isSet( %4$s POST['firstname'] ) ? %4$s POST['firstname'] : '';
$preferredname = isSet( %4$s POST['preferredname'] ) ? %4$s POST['preferredname'] : '';
$surname = isSet( %4$s POST['surname'] ) ? %4$s POST['surname'] : '';
$email = isSet( %4$s POST['email'] ) ? %4$s POST['email'] : '';
$street = isSet( %4$s POST['street'] ) ? %4$s POST['street'] : '';
$apartmentno = isSet( %4$s POST['apartmentno'] ) ? ]%4$s POST['apartmentno'] : '';
$city = isSet( %4$s POST['city'] ) ? %4$s POST['city'] : '';
$state = isSet( %4$s POST['state'] ) ? %4$s POST['state'] : '';
$zipcode = isSet( %4$s POST['zipcode'] ) ? %4$s POST['zipcode'] : '';
$country = isSet( %4$s POST['country'] ) ? %4$s POST['country'] : '';
$daytimetel = isSet( %4$s POST['daytimetel'] ) ? %4$s POST['daytimetel'] : '';
$cancallday = isSet( %4$s POST['cancallday'] ) ? %4$s POST['cancallday'] : '';
$eveningtel = isSet(%4$s POST['eveningtel'] ) ? %4$s POST['eveningtel'] : '';
$cancallevevenin = isSet( %4$sPOST['cancallevenin'] ) ? %4$s POST['cancallevenin'] : '';
$onething = isSet( %4$s POST['onething'] ) ? %4$s POST['onething'] : ''
 
//-------VAILDATION
if( ! $firstname 

$error.="Please, go back and fill out your first name<br />\n"
};
if( ! 
$surname 

$error.="Please, go back and fill out your surname<br />\n"
};
if( ! 
$email 

$error.="Please, go back and fill out your email address<br />\n"
};
if( ! 
$street 

$error.="Please, go back and fill out your house number and street name<br />\n"
};
if( ! 
$city 

$error.="Please, go back and fill out your city<br />\n"
};
if( ! 
$state 

$error.="Please, go back and fill out your state<br />\n"
};
if( ! 
$country 

$error.="Please, go back and fill out your country of residence<br />\n"
};
if( ! 
$daytimetel 

$error.="Please, go back and fill out your daytime telephone number<br />\n"
};
if( ! 
$eveningtel 

$error.="Please, go back and fill out your evening telephone number<br />\n"
}
if( ! 
$onething 

$error.="Please, go back and fill out your one thing to focus on<br />\n";
}
$error.="Sorry, but the form cannot be sent until the fields indicated are filled out completely:
first name is required
house number/street name is required
city is required
state is required
country of reidence is required
daytime telephone number is required
evening telephone number is required
one thing to focus on is required
//This is line 79// Please use your "
Back" button to return to the form to correct the omissions, thank you\n"
};
//-------->ERROR FREE??
if($error==""){
echo 
"Thank you for inquiring about icoachdads.com! A receipt of your submission will be e-mailed to you almost immediately.";
 
//----------------------------------
$mailContent="--------CONTACT--------\n"
."title: ".$title."\n"
."firstname: ".$firstName."\n"
."preferredname: ".$preferedname."\n"
."surname: ".$surname."\n"
."email: ".$email."\n\n--------ADDRESS--------\n"
."street: ".$street."\n"
."apartmentnumber: ".$apartmentno."\n"
."city: ".$city."\n"
."state: ".$state."\n"
."zipcode: ".$zipcode."\n"
."country: ".$couontry."\n"
."daytimetelephone: ".$dattimetel."\n\n--------PHONE--------\n"
."Cancallindaytime: ".$cancallday."\n"
."eveningtelephone: ".$eveningtel."\n"
."cancallinevening: ".$cancallevenin."\n"
."onething: ".$onething."\n";
//----------------------------------
$toAddress="forms@icoachdads.com";
$subject="icoachdads.com's free coaching session'";
$recipientSubject="icoachdads.com's Contact Form";
$receiptMessage "Thank you ".$firstName." for inquiring about icoachdads.com's free coaching session!\n\n\nHere is what you submitted to me:\n\n";
"--------CONTACT--------\n"
."Title: ".$title."\n"
."First Name: ".$firstname."\n"
."Preferred Name: ".$preferedname."\n"
."Surname: ".$surname."\n"
."E-mail: ".$email."\n\n--------ADDRESS--------\n"
."Street: ".$street."\n"
."Apartment Number: ".$apartmentno."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Zipcode: ".$zipcode."\n"
."Country: ".$country."\n"
."Daytime telephone: ".$daytimetel."\n\n--------PHONE--------\n"
."Can call in daytime: ".$cancallday."\n"
."Evening telephone: ".$eveningtel."\n"
."Can call in evening: ".$cancallevenin."\n"
."One thing: ".$onething."\n";
//----------------------------------
mail($email$subject$receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;
 
//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("localhost","#####""####") or die("Unable to connect!"); /* change this! */
 
mysql_select_db("####") or die("Unable to select database!"); /* change this! */
 
// EXECUTE QUERY --->
$query="INSERT INTO #### (
title,
firstname,
preferredname,
surname,
email,
street,
apartmentno,
city,
state,
zipcode,
country,
daytimetel,
cancallday,
eveningtel,
cancallevenin,
onething)
VALUES(
'"
.$title."',
'"
.$firstname."',
'"
.$preferredname."',
'"
.$surname."',
'"
.$email."',
'"
.$street."',
'"
.$apartmentno."',
'"
.$city."',
'"
.$state."',
'"
.$zipcode."',
'"
.$country."',
'"
.$daytimetel."',
'"
.$cancallday."',
'"
.$eveningtel."',
'"
.$cancallevenin."',
'"
.$onething."')";
//////----->
$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 - \n";
print 
"$error\n";
print 
"\n";
print 
"\n";
print 
"Please use your \"Back\" button to return to the form to correct the omissions. Thank you.\n";


Reply With Quote
  #5  
Old February 7th, 2005, 04:17 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by moggi1964
I didn't realise the button next to the #existed and I tried to wrap the text but it didn't work!!


You will note that the php button puts in the php tags ( [ PHP ] and [ /PHP ] ). You can also type this by hand, try editing your above post and put the [ PHP ] (no spaces) at the beginning of your code and [ /PHP ] at the end of the code block, not each line!

It will look a lot better on scr