aebstract Posted March 14, 2007 Share Posted March 14, 2007 I have a contact form and I want the information to enter in to the database, though it isn't entering anything in to the database. My code for the page is listed below, much thanks for taking time to help! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Hill Marketing Group - Atlanta Web Design Programming - Websites Banners HTML Mailers Flash E-Commerce PHP CSS MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <?php include ("meta.php"); ?> <link href="stylesheet.css" rel="stylesheet" type=text/css title=default /> </head> <body> <div id="container"> <div id="ctop"> <div id="logotrans"><a href="http://hillmarketinggroup.com"><img src="logotrans.gif" border="0" title="Hill Marketing Group: Atlanta Web Design & Programming" alt="Hill Marketing Group: Atlanta Web Design & Programming" /></a></div> <div id="nav"> <?php include ("nav.php"); ?> </div> </div> <div id="contentheader2"> <div id="contentcatagory">contact</div> <div style="width:140px; height:35px; float:right; "><a href="requestquote.php"><img src="spacer.gif" border="0" /></a></div> </div> <div> <table width="735px" height="218px" cellpadding="0" cellspacing="0"> <tr> <td width="19" style="background-image: url(leftcontentbg.jpg); "></td><td width="701" bgcolor="#FFFFFF" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php header("Cache-control: private"); if(isset($sent)) { $content2 .= 'Your message has been sent.'; } if(!isset($sent)) { if (isset ($_POST['submit'])) { $problem = FALSE; if ($problem == TRUE) { $content .= 'Errors:<br />'; } if (empty ($_POST['firstname'])) { $problem = TRUE; $content .= 'Name is required<br />'; } if (empty ($_POST['email'])) { $problem = TRUE; $content .= 'Email Address is required.<br />'; }elseif (!preg_match("/.*@.*..*/", $_POST['email']) OR preg_match("/(<|>)/", $_POST['email'])) { $problem = TRUE; $content .= 'The email address you chose was incorrect<br />'; } if (empty ($_POST['body'])) { $problem = TRUE; $content .= 'You are required to submit a message.<br />'; } if (!$problem) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $body = $_POST['body']; $company = $_POST['company']; $website = $_POST['website']; $telephone = $_POST['telephone']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; mysql_connect("localhost","hmg","hillpass"); mysql_select_db("hmg"); $query = "INSERT INTO contact (id,type,read,firstname,lastname,email,body,company,website,telephone,address,city,state,zip) VALUES (null,0,0,$firstname,$lastname,$email,$body,$company,$website,$telephone,$address,$city,$state,$zip)"; mysql_query($query); $sendmail = " firstname - $firstname email - $email $body"; $sendmail2 = "Hi $firstname $lastname, This is an automatic message sent to confirm that your message has been sent and we will get back with you as soon as possible. Thanks, Hill Marketing Group"; mail ('[email protected]', 'Contact Form', $sendmail, 'From: $email'); mail ($email, 'Message received', $sendmail2, "From: [email protected]"); header ("Location: index.php?menu=contact&sent"); $content .= '<font size="2" face="Arial" color="#000000">Thank you for contacting us. Your message has been received.</font> <br />'; } else { } } $content .= ' <table width="350" border="0" align="center" cellpadding="4" cellspacing="3"> <tr> <td height="38" colspan="2" bgcolor="#FFFFFF"><p><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><strong><font color="#000000" size="3"><font size="2">HILL MARKETING GROUP, LLC.</font></font></strong></font></font></p></td> </tr> <tr> <td valign="top"width="63%" bgcolor="#F6F6F6"><font size="2" face="Arial, Helvetica, sans-serif"><strong> General Info:<br><br> </strong> <div class="ccc"><a href="mailto:[email protected]">[email protected]</div><br> </a><br> </font><font size="2" face="Arial, Helvetica, sans-serif"><strong> Careers:</strong><br><br> <div class="ccc"><a href="mailto:[email protected]">[email protected]</a></div><br> <br> </font></td> <td valign="top"width="37%" bgcolor="#F6F6F6"><p><font size="2" face="Arial, Helvetica, sans-serif"><strong> Phone:</strong> <br> 770.366.7532</font></p> <p><font size="2" face="Arial, Helvetica, sans-serif"><strong> Fax:</strong><br> 770.454.8589<br> <br> </font></p></td> <td></td><td> <form action="contact.php" method="post"> <table border="0" cellpadding="2"> <tr> <td align="left" valign="middle" bgcolor="#eeeeee"><font size="1" face="Arial" color="#000000"><font size="1" face="Arial" color="#000000"><strong>Name</strong></font> </td><td valign="top" bgcolor="#FFFFFF"><input type="text" class="texta" name="firstname" maxlength="20" size="20" value="' . $_POST['firstname'] . '" /></td> </tr> <tr> <td align="left" valign="middle" bgcolor="#eeeeee"><font size="1" face="Arial" color="#000000"><font size="1" face="Arial" color="#000000"><strong>E-Mail</strong></font> </td><td valign="top" bgcolor="#FFFFFF"><input type="text" class="texta" name="email" maxlength="50" size="20" value="' . $_POST['email'] . '" /></td> </tr> <tr> <td align="left" valign="middle" bgcolor="#eeeeee"><font size="1" face="Arial" color="#000000"><font size="1" face="Arial" color="#000000"><strong>Message </strong></font></td><td valign="top" bgcolor="#FFFFFF"><textarea name="body" rows="3" cols="15" class="textfieldmsg"></textarea></td> </tr> <tr> <td></td> <td> <input type="submit" name="submit" value="Talk To Us!" style="background-color: #525252; border: 1px solid orange; border-style:none; color: #FFFFFF; padding: 2px;" class="textsubmit" /> </td></tr> </table> </form> </td> </tr> </table>'; } echo "$content"; ?> </td> <td> </td> </tr> </table> </td><td width="15" height="218" style="background-image: url(contentbgright.jpg); "></td> </tr> </table> </div> <div id="bottom2"> <div id="copyright"> <?php include ("copyright.php"); ?> </div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/ Share on other sites More sharing options...
papaface Posted March 14, 2007 Share Posted March 14, 2007 VALUES (null,0,0,$firstname,$lastname,$email,$body,$company,$website,$telephone,$address,$city,$state,$zip)"; should be: VALUES ('null','0','0','$firstname','$lastname','$email','$body','$company','$website','$telephone','$address','$city','$state','$zip')"; You should also put variables into SQL like this: VALUES ('{$firstname}',' //etc Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207188 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 Just an fyi: if ($problem == TRUE) { $content .= 'Errors:<br />'; } is better stated like this: if ($problem) { $content .= 'Errors:<br />'; } No need to set it == TRUE as the if statement will recognize it on it's own. Also I would add this: mysql_query($query) or DIE(mysql_error()); So you know if there is an error there. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207190 Share on other sites More sharing options...
papaface Posted March 14, 2007 Share Posted March 14, 2007 You should also mysql_real_escape_string(); everything before you put variables into the database. Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207191 Share on other sites More sharing options...
aebstract Posted March 14, 2007 Author Share Posted March 14, 2007 Okay, I did both changes that you guys mentioned. Here is the error I got, along with updated code: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read,firstname,lastname,email,body,company,website,telephone,address,city,state,' at line 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Hill Marketing Group - Atlanta Web Design Programming - Websites Banners HTML Mailers Flash E-Commerce PHP CSS MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <?php include ("meta.php"); ?> <link href="stylesheet.css" rel="stylesheet" type=text/css title=default /> </head> <body> <div id="container"> <div id="ctop"> <div id="logotrans"><a href="http://hillmarketinggroup.com"><img src="logotrans.gif" border="0" title="Hill Marketing Group: Atlanta Web Design & Programming" alt="Hill Marketing Group: Atlanta Web Design & Programming" /></a></div> <div id="nav"> <?php include ("nav.php"); ?> </div> </div> <div id="contentheader2"> <div id="contentcatagory">contact</div> <div style="width:140px; height:35px; float:right; "><a href="requestquote.php"><img src="spacer.gif" border="0" /></a></div> </div> <div> <table width="735px" height="218px" cellpadding="0" cellspacing="0"> <tr> <td width="19" style="background-image: url(leftcontentbg.jpg); "></td><td width="701" bgcolor="#FFFFFF" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php header("Cache-control: private"); if(isset($sent)) { $content2 .= 'Your message has been sent.'; } if(!isset($sent)) { if (isset ($_POST['submit'])) { $problem = FALSE; if ($problem == TRUE) { $content .= 'Errors:<br />'; } if (empty ($_POST['firstname'])) { $problem = TRUE; $content .= 'Name is required<br />'; } if (empty ($_POST['email'])) { $problem = TRUE; $content .= 'Email Address is required.<br />'; }elseif (!preg_match("/.*@.*..*/", $_POST['email']) OR preg_match("/(<|>)/", $_POST['email'])) { $problem = TRUE; $content .= 'The email address you chose was incorrect<br />'; } if (empty ($_POST['body'])) { $problem = TRUE; $content .= 'You are required to submit a message.<br />'; } if (!$problem) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $body = $_POST['body']; $company = $_POST['company']; $website = $_POST['website']; $telephone = $_POST['telephone']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; mysql_connect("localhost","hmg","hillpass"); mysql_select_db("hmg"); $query = "INSERT INTO contact (id,type,read,firstname,lastname,email,body,company,website,telephone,address,city,state,zip) VALUES ('null','0','0','$firstname','$lastname','$email','$body','$company','$website','$telephone','$address','$city','$state','$zip')"; mysql_query($query) or DIE(mysql_error()); $sendmail = " firstname - $firstname email - $email $body"; $sendmail2 = "Hi $firstname $lastname, This is an automatic message sent to confirm that your message has been sent and we will get back with you as soon as possible. Thanks, Hill Marketing Group"; mail ('[email protected]', 'Contact Form', $sendmail, 'From: $email'); mail ($email, 'Message received', $sendmail2, "From: [email protected]"); header ("Location: index.php?menu=contact&sent"); $content .= '<font size="2" face="Arial" color="#000000">Thank you for contacting us. Your message has been received.</font> <br />'; } else { } } $content .= ' <table width="350" border="0" align="center" cellpadding="4" cellspacing="3"> <tr> <td height="38" colspan="2" bgcolor="#FFFFFF"><p><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><strong><font color="#000000" size="3"><font size="2">HILL MARKETING GROUP, LLC.</font></font></strong></font></font></p></td> </tr> <tr> <td valign="top"width="63%" bgcolor="#F6F6F6"><font size="2" face="Arial, Helvetica, sans-serif"><strong> General Info:<br><br> </strong> <div class="ccc"><a href="mailto:[email protected]">[email protected]</div><br> </a><br> </font><font size="2" face="Arial, Helvetica, sans-serif"><strong> Careers:</strong><br><br> <div class="ccc"><a href="mailto:[email protected]">[email protected]</a></div><br> <br> </font></td> <td valign="top"width="37%" bgcolor="#F6F6F6"><p><font size="2" face="Arial, Helvetica, sans-serif"><strong> Phone:</strong> <br> 770.366.7532</font></p> <p><font size="2" face="Arial, Helvetica, sans-serif"><strong> Fax:</strong><br> 770.454.8589<br> <br> </font></p></td> <td></td><td> <form action="contact.php" method="post"> <table border="0" cellpadding="2"> <tr> <td align="left" valign="middle" bgcolor="#eeeeee"><font size="1" face="Arial" color="#000000"><font size="1" face="Arial" color="#000000"><strong>Name</strong></font> </td><td valign="top" bgcolor="#FFFFFF"><input type="text" class="texta" name="firstname" maxlength="20" size="20" value="' . $_POST['firstname'] . '" /></td> </tr> <tr> <td align="left" valign="middle" bgcolor="#eeeeee"><font size="1" face="Arial" color="#000000"><font size="1" face="Arial" color="#000000"><strong>E-Mail</strong></font> </td><td valign="top" bgcolor="#FFFFFF"><input type="text" class="texta" name="email" maxlength="50" size="20" value="' . $_POST['email'] . '" /></td> </tr> <tr> <td align="left" valign="middle" bgcolor="#eeeeee"><font size="1" face="Arial" color="#000000"><font size="1" face="Arial" color="#000000"><strong>Message </strong></font></td><td valign="top" bgcolor="#FFFFFF"><textarea name="body" rows="3" cols="15" class="textfieldmsg"></textarea></td> </tr> <tr> <td></td> <td> <input type="submit" name="submit" value="Talk To Us!" style="background-color: #525252; border: 1px solid orange; border-style:none; color: #FFFFFF; padding: 2px;" class="textsubmit" /> </td></tr> </table> </form> </td> </tr> </table>'; } echo "$content"; ?> </td> <td> </td> </tr> </table> </td><td width="15" height="218" style="background-image: url(contentbgright.jpg); "></td> </tr> </table> </div> <div id="bottom2"> <div id="copyright"> <?php include ("copyright.php"); ?> </div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207194 Share on other sites More sharing options...
papaface Posted March 14, 2007 Share Posted March 14, 2007 If ID is auto_increment you dont specifty an input for it. That applies for anything else that is auto-generated. Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207197 Share on other sites More sharing options...
aebstract Posted March 14, 2007 Author Share Posted March 14, 2007 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read,firstname,lastname,email,body,company,website,telephone,address,city,state,' at line 1 $query = "INSERT INTO contact (type,read,firstname,lastname,email,body,company,website,telephone,address,city,state,zip) VALUES ('0','0','$firstname','$lastname','$email','$body','$company','$website','$telephone','$address','$city','$state','$zip')"; I had it there at first cause I wasn't sure if it had to be removed or not. This is the new code + the error message to go along with it. Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207205 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 Either type or read is a reserved word in MySQL to fix this one of 2 things, rename them to something different or add `columnname`, `columnname2` to all your column names. Remember it is ` not single quote ' --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207209 Share on other sites More sharing options...
aebstract Posted March 14, 2007 Author Share Posted March 14, 2007 Thank you, I added a letter on to each of those and it seems to have fixed the problem. Quote Link to comment https://forums.phpfreaks.com/topic/42702-solved-not-entering-in-to-db/#findComment-207213 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.