Emma316 Posted July 20, 2006 Share Posted July 20, 2006 This is the error:[quote]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 ''querys' (queryid, from, subject, body) VALUES ('596581134692432766302226', 'ema' at line 1[/quote]This is the source:[code]<html><head><title>Support - Create Query</title></head><body><?PHP $mailto = '[email protected]';$instance = $_POST['instance'];$subject = $_POST['subject'];$from = $_POST['from'];$body = $_POST['body'];$primary = 'root';$key = '';$location = 'support';if(!$instance){?><form action="makemail.php" method="post">Subject: <input type="text" name="subject"/><br />*E-mail: <input type="text" name="from"/><br />*Message:<br /><textarea name="body" cols="55" rows="25"></textarea><br /><input type="hidden" name="instance" value="1" /><input type="submit" name="send" /></form><?}else{if (!$from){die('Required field left blank. <meta http-equiv="refresh" content="2;">Redirecting, please wait...');}elseif (!$body){die('Required field left blank. <meta http-equiv="refresh" content="2;">Redirecting, please wait...');}$x = 0;while ($x <= 23){$queryid=$queryid . rand(0,9);$x++;}$check = $queryid;mysql_connect(localhost,$primary,$key);@mysql_select_db($location) or die(mysql_error());$query = "INSERT INTO 'querys' (queryid, from, subject, body) VALUES ('$queryid', '$from', '$subject', '$body')";mysql_query($query) or die(mysql_error());mysql_close(); //Closeprint ('An e-mail has been sent to you with information regarding your support query. Please check your inbox.');print ('<meta http-equiv="refresh" content="5;"><br>Redirecting, please wait...');}?>[/code]This is a support query form script which is still under construction, but I wont be able to move onto the next part (e-mail sending stuff) until I get past the error code.. a couple things (aka sql user/pass and e-mail changed) but other than that its all the same. If you know why I'm getting the error, please help me to fix it. Link to comment https://forums.phpfreaks.com/topic/15113-this-is-probably-a-stupid-question-please-answer/ Share on other sites More sharing options...
localhost Posted July 20, 2006 Share Posted July 20, 2006 Try this:[code]$query = "INSERT INTO `querys` (`queryid`, `from`, `subject`, `body`) VALUES ('$queryid', '$from', '$subject', '$body')";$result = mysql_query($query) or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/15113-this-is-probably-a-stupid-question-please-answer/#findComment-60870 Share on other sites More sharing options...
Emma316 Posted July 20, 2006 Author Share Posted July 20, 2006 So field names have to be in quotes? Ok thanks :) Link to comment https://forums.phpfreaks.com/topic/15113-this-is-probably-a-stupid-question-please-answer/#findComment-60871 Share on other sites More sharing options...
localhost Posted July 20, 2006 Share Posted July 20, 2006 Did it work?Usually thats how I do my Insert queries. Link to comment https://forums.phpfreaks.com/topic/15113-this-is-probably-a-stupid-question-please-answer/#findComment-60876 Share on other sites More sharing options...
wildteen88 Posted July 20, 2006 Share Posted July 20, 2006 [quote author=Emma316 link=topic=101198.msg400275#msg400275 date=1153381506]So field names have to be in quotes? Ok thanks :)[/quote]Emma ideally they are supposed to be in quotes but not many people do. But the real reason why your query fails was because you are using a mysql keyword for a field name - fromMySQL was getting confused when it came uppon the word from. When you place it in backticks - `from` - MySQL then wont get confused and use from as the field name. Link to comment https://forums.phpfreaks.com/topic/15113-this-is-probably-a-stupid-question-please-answer/#findComment-60890 Share on other sites More sharing options...
Emma316 Posted July 20, 2006 Author Share Posted July 20, 2006 @localhost Yes it worked just fine, thanks alot ^^@wildteen88 Thanks, if people actually told me [i]how it actually works and why[/i], I wouldn't have so many problems.. once a person understands the principle (spelling) then correcting typos and things is a breeze. By the way, this is my 5th php script to make ever what do you all think?@People writing tutorials and faqs -- please remember what I said to wildteen88. Link to comment https://forums.phpfreaks.com/topic/15113-this-is-probably-a-stupid-question-please-answer/#findComment-60920 Share on other sites More sharing options...
wildteen88 Posted July 20, 2006 Share Posted July 20, 2006 Sorry for the spelling mistakes. Also I did try to explain it as best as I could. Or am I getting my wires crossed here?Also most tutorials now adays take you on a copy 'n' paste session, and dont bother explaining the code. Link to comment https://forums.phpfreaks.com/topic/15113-this-is-probably-a-stupid-question-please-answer/#findComment-60927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.