wright67uk Posted February 25, 2011 Share Posted February 25, 2011 Would anybody be able to offer advice on a syntax isssue I have? $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; $companyname = $_GET['companyname']; $doornumber = $_GET ['doornumber']; $street = $_GET ['street']; $town = $_GET['town']; $postcode = $_GET['postcode']; $useremail = $_GET ['useremail']; $telephone = $_GET['telephone']; $shortcode = substr($postcode,0,2); $query =mysql_query ("SELECT useremail FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>"; $message = "$firstname $lastname, from $town has searched for your details.\r\nYou may contact them on $telephone.\r\nThankyou."; $subject = "You Showed Up In The Tree Directory!"; $email = "$nt[0],$nt[1],$nt[2]"; $to = "$email"; mail( "$to", "$subject","$message", "$headers"); $message = "Thankyou for using the Tree Directory!\r\nThe email addresses that you have requested are;\r\n$nt[0]\r\n$nt[1]\r\n$nt[2]\r\n"; $email = "$useremail"; $to = "$useremail"; $subject = "Your Tree Directory Search Results"; mail( "$to", "$subject","$message", "$headers"); $query =mysql_query ("INSERT INTO customers ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) ") ; echo mysql_error(); ?></body></html> My error message is; 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 '678, hbkjh, vgvi, EN7 6PX, [email protected], 879086767869hv) (fir' at line 2 This refers to random input which I have typed into my html form. I can assume this error is in relation to; $query =mysql_query ("INSERT INTO customers ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) ") as I have just added it. Please can anyone advise me as to how my syntax should look? Link to comment https://forums.phpfreaks.com/topic/228855-php-to-sql-a-bit-doolally/ Share on other sites More sharing options...
EmlynK Posted February 25, 2011 Share Posted February 25, 2011 You could try: $query =mysql_query ("INSERT INTO customers (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) VALUES('$firstname', '$lastname', '$doornumber', '$street', '$town', '$postcode', '$useremail', '$telephone') ") Not sure if it would work though.... Link to comment https://forums.phpfreaks.com/topic/228855-php-to-sql-a-bit-doolally/#findComment-1179796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.