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: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\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, edward_t_wright@hotmail.co.uk, 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? Quote Link to comment https://forums.phpfreaks.com/topic/228856-syntax-when-running-a-2nd-query/ Share on other sites More sharing options...
trq Posted February 26, 2011 Share Posted February 26, 2011 Strings need to be surrounded by quotes within SQL queries. Quote Link to comment https://forums.phpfreaks.com/topic/228856-syntax-when-running-a-2nd-query/#findComment-1179842 Share on other sites More sharing options...
fenway Posted February 26, 2011 Share Posted February 26, 2011 ...which would be easy to see if you were looking at raw SQL. Quote Link to comment https://forums.phpfreaks.com/topic/228856-syntax-when-running-a-2nd-query/#findComment-1180140 Share on other sites More sharing options...
Muddy_Funster Posted March 2, 2011 Share Posted March 2, 2011 this is back to front... ("INSERT INTO customers ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) ") should be ("INSERT INTO customers (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) VALUES ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) ") The others have already told you that you need to put your input strings inside quotes. Quote Link to comment https://forums.phpfreaks.com/topic/228856-syntax-when-running-a-2nd-query/#findComment-1181738 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.