Jump to content

Archived

This topic is now archived and is closed to further replies.

Emma316

This is probably a stupid question, please answer?

Recommended Posts

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 = '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...');
}
?>[/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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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 - 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.

Share this post


Link to post
Share on other sites
@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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.