Jump to content

[SOLVED] You have an error in your SQL syntax;


overlordofevil

Recommended Posts

so as the subject says it errors out on my code when I try to run it.

 

The full error 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 '' at line 1

 

I can't find the problem, I am only getting this error when I upload the files to my website for testing but when I run it on my test server here in the office the code works fine. I double checked and the mysql on both machines are version 5.

 

Here's the code, please let me know if you see the error or what I can look at.

 

<?php 
session_start();

?>
<html>
<body>
<?php

include ("misc.inc");
include ("functions.inc");

$chid = $_SESSION['chapter_id'];

$query = "SELECT * FROM demographics join id ON ( id.id = demographics.id ) where id.chid='$chid' ORDER BY demographics.lastname, demographics.firstname";
$result = mysql_query($query) or die (" Line 1 Query failed due to: ".mysql_error());

echo "<table border='1' cellspacing='15'>";
echo "<tr><td colspan='12'><hr></td></tr>";
echo "<tr><td>Character's ID</td><td>Character's' Name</td><td>Class</td><td>Race</td><td>Subrace</td><td>Player's Name</td><td>Character Sheet</td><td>XP Log</td><td>Spirit Forge?</td><td>Race Change?</td></tr>";
while ($row = mysql_fetch_array($result))
{
extract($row);
$uid = $row[id];
$pname = getplayersname($uid);

$query1 = "SELECT * FROM characters where id='$uid' ORDER BY wchar";
$result1 = mysql_query($query1) or die (" Line 2 Query failed due to: ".mysql_error());
while ($row1= mysql_fetch_array($result1))
{
extract($row1);
$cname = "$firstname $lastname";
$racename = getracename($race);
$classname = getclassname($clas);
echo "<tr><td><a href='display.php?action=viewplayer&cid=$cid'>$cid</a></td><td>$cname</td><td>$classname</td><td>$racename</td><td>$subrace</td><td>$pname</td><td><a href='charsheet.php?action=viewplayer&cid=$cid'>Character Sheet</a></td><td><a href='charxplog.php?action=viewplayer&cid=$cid'>XP Log</a></td><td><a href='spiritforge.php?action=viewplayer&cid=$cid'>Spirit Forge</a></td><td><a href='racechange.php?action=viewplayer&cid=$cid'>Race Change</a></td></tr>\n";
}
}
echo "<tr><td colspan='12'><hr></td></tr>\n";
echo "</table>\n";
?>
</body>
</html>

 

any help is appreciated.

 

Thanks

Link to comment
Share on other sites

::bump::

Still having problems with the scripts. I have tried to rewrite it and even changed up the order of the queries but it still gives me the sql error on my web server but it works fine on my test server just really confused why it would do this.

 

Any ideas or help would be appreciated. 

Link to comment
Share on other sites

I'll take a guess that it is your first query (the second query is dependent on the first one working), and since there is only one place in that query string where there are single quotes, I'll also guess that $chid in the following portion of that query is empty/null. - where id.chid='$chid'

 

Add the following two lines after your first opening <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

And if that does not provide any useful information, you will need to show the code where $_SESSION['chapter_id']; is being set.

Link to comment
Share on other sites

Your code is outputting information with the mysql error message as to which query failed -

 

" Line 1 Query failed due to: " ...

 

or

 

" Line 2 Query failed due to: " ...

 

That would tell which query failed (As I stated, I was taking a guess.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.