944,117 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2064
  • PHP RSS
May 13th, 2005
0

Error in mailer script

Expand Post »
This has an error way down at the $result=mysql_query($query) line.

Anyone knows whats up? Or could it be my login info? Is localhost bad?

[PHP]
<?php
/* grabs the POST variables and puts them into variables that we can use */
$email=$_POST['email'];
$city=$_POST['city'];
$state=$_POST['state'];

//---------VALIDATION-------->
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail 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
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for subscribing! A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
."E-mail: ".$email."\n"
."City: ".$city."\n"
."State: ".$state."\n";
//----------------------------------
$toAddress="subscribe@whatsupinnh.com"; /* change this! */
$subject="Subscription"; /* change this! */
$recipientSubject="You are subscribed to the Whats Up In NH newsletter."; /* change this! */
$receiptMessage = "Thank you for joining WhatsUpInNH.com's Newsletter!\n\n\nHere is what you submitted to us:\n\n"
."--------CONTACT--------\n"
."E-mail: ".$email."\n"
."City: ".$city."\n"
."State: ".$state."\n";
//----------------------------------
mail($email, $subject, $receiptMessage,"FromtoAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"Fromemail");
//--->echo $mailContent;

//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("localhost","mylogin", "mypassword ") or die("Unable to connect!"); /* change this! */

mysql_select_db("database") or die("Unable to select database!"); /* change this! */

// EXECUTE QUERY --->
$query="INSERT INTO generalContact (
email,
city,
state;
VALUES(
'".$email."',
'".$city."',
'".$state."';
//////----->
$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";
}

?> [/PHP]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
4BoredomDotCom is offline Offline
9 posts
since Mar 2005
May 16th, 2005
0

Re: Error in mailer script

anyone? nmn
Reputation Points: 10
Solved Threads: 0
Newbie Poster
4BoredomDotCom is offline Offline
9 posts
since Mar 2005
Jun 6th, 2005
0

Re: Error in mailer script

what does the mysql_error tell you is happening?
Reputation Points: 15
Solved Threads: 0
Junior Poster in Training
barnamos is offline Offline
50 posts
since Mar 2005
Jun 6th, 2005
0

Re: Error in mailer script

Wrong
[PHP]$query="INSERT INTO generalContact (
email,
city,
state;
VALUES(
'".$email."',
'".$city."',
'".$state."'; [/PHP]

Correct
[PHP]
$query="INSERT INTO generalContact (
email,
city,
state)
VALUES('$email', '$city', '$state')"; [/PHP]

Your corrected source code
[PHP]
/* grabs the POST variables and puts them into variables that we can use */
$email=$_POST['email'];
$city=$_POST['city'];
$state=$_POST['state'];

//---------VALIDATION-------->
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail 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
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for subscribing! A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
."E-mail: ".$email."\n"
."City: ".$city."\n"
."State: ".$state."\n";
//----------------------------------
$toAddress="subscribe@whatsupinnh.com"; /* change this! */
$subject="Subscription"; /* change this! */
$recipientSubject="You are subscribed to the Whats Up In NH newsletter."; /* change this! */
$receiptMessage = "Thank you for joining WhatsUpInNH.com's Newsletter!\n\n\nHere is what you submitted to us:\n\n"
."--------CONTACT--------\n"
."E-mail: ".$email."\n"
."City: ".$city."\n"
."State: ".$state."\n";
//----------------------------------
mail($email, $subject, $receiptMessage,"FromtoAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"Fromemail");
//--->echo $mailContent;

//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("localhost","mylogin", "mypassword ") or die("Unable to connect!"); /* change this! */

mysql_select_db("database") or die("Unable to select database!"); /* change this! */

// EXECUTE QUERY --->
$query="INSERT INTO generalContact (
email,
city,
state)
VALUES('$email', '$city', '$state')";
//////----->
$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";
}

[/PHP]
PoA
Reputation Points: 19
Solved Threads: 9
Posting Whiz in Training
PoA is offline Offline
234 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php skin
Next Thread in PHP Forum Timeline: Accidently blocked a cookie-please help!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC