Jump to content


Photo

This is probably a stupid question, please answer?


  • Please log in to reply
6 replies to this topic

#1 Emma316

Emma316
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 July 2006 - 07:37 AM

This is the error:

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


This is the source:

<html>
<head>
<title>Support - Create Query</title></head>
<body>
<?PHP 
$mailto = 'admin@site.net';
$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(); //Close
print ('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...');
}
?>
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.

#2 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 20 July 2006 - 07:43 AM

Try this:


$query = "INSERT INTO `querys` (`queryid`, `from`, `subject`, `body`) VALUES ('$queryid', '$from', '$subject', '$body')";
$result = mysql_query($query) or die(mysql_error());



#3 Emma316

Emma316
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 July 2006 - 07:45 AM

So field names have to be in quotes?  Ok thanks :)

#4 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 20 July 2006 - 08:10 AM

Did it work?

Usually thats how I do my Insert queries.

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 July 2006 - 09:19 AM

So field names have to be in quotes?  Ok thanks :)

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 - from
MySQL 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.

#6 Emma316

Emma316
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 July 2006 - 10:35 AM

@localhost Yes it worked just fine, thanks alot ^^
@wildteen88 Thanks, if people actually told me how it actually works and why, 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.

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 July 2006 - 10:44 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users