overlordofevil Posted April 24, 2008 Share Posted April 24, 2008 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted April 24, 2008 Share Posted April 24, 2008 what does echo $query; give? Quote Link to comment Share on other sites More sharing options...
overlordofevil Posted April 24, 2008 Author Share Posted April 24, 2008 echo $query ?? sorry not following you can you explain a bit Quote Link to comment Share on other sites More sharing options...
overlordofevil Posted April 28, 2008 Author Share Posted April 28, 2008 ::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. Quote Link to comment Share on other sites More sharing options...
Steven8294 Posted April 28, 2008 Share Posted April 28, 2008 Dude, dunno if this will help bbut place your includes before you start html.. where you start the session.. and btw where do you actually connect to the database.. my files all say include "db_connect.php" ect.. Quote Link to comment Share on other sites More sharing options...
Steven8294 Posted April 28, 2008 Share Posted April 28, 2008 <?php session_start(); >>>include "includes/db_connect.php";<<< include "includes/functions.php"; logincheck(); $username=$_SESSION['username']; $viewuser=$_GET['viewuser']; :-\ Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 28, 2008 Share Posted April 28, 2008 When barand says echo $query, he means print out the query that you generated and see if it is correct. Here are some MySQL/PHP debugging tips that may help you understand what barand meant by 'echo $query': http://www.phpcodinghelp.com/article.php?article=debug#tips_mysql Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 28, 2008 Share Posted April 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
Steven8294 Posted April 28, 2008 Share Posted April 28, 2008 where can i get error reporting..? Quote Link to comment Share on other sites More sharing options...
overlordofevil Posted April 28, 2008 Author Share Posted April 28, 2008 thanks for the help I will try this stuff out. I just wasn't sure where it was failing at.. hmmm... anyway thanks again. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 28, 2008 Share Posted April 28, 2008 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.) Quote Link to comment Share on other sites More sharing options...
overlordofevil Posted April 28, 2008 Author Share Posted April 28, 2008 thanks for the help with finding the error. simple syntax error where I forgot to use '' around a variable being pulled. Also didn't help that one of the variables was named differently in the db. Thanks Again Quote Link to comment 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.