| | |
Error in mailer script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2005
Posts: 9
Reputation:
Solved Threads: 0
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,"From
toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From
email");
//--->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]
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,"From
toAddress"); //----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From
email"); //--->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]
•
•
Join Date: Jul 2004
Posts: 234
Reputation:
Solved Threads: 8
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,"From
toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From
email");
//--->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]
[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,"From
toAddress");//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From
email");//--->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
- "error has occured in script on this page" (Windows NT / 2000 / XP)
- Error message when running ASP email script (ASP)
Other Threads in the PHP Forum
- Previous Thread: php skin
- Next Thread: Accidently blocked a cookie-please help!!
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary body broken cakephp checkbox class cms code cron curl database date date/time display dynamic echo email error file files folder form forms function functions global google href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail memmory menu mlm mod_rewrite msqli_multi_query multiple mycodeisbad mysql navigation oop parameter paypal pdf php problem query radio random recourse recursion regex registrationform remote script search seo server sessions sms soap source space sql static syntax system table tutorial update upload url validation validator variable video web webdesign wordpress xml youtube





