Styles2304 Posted September 7, 2007 Share Posted September 7, 2007 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 'query' at line 1 Code <?php include "conn.inc.php"; include "auth.inc.php"; if ($_SESSION['user_permission'] != 10) { echo "Sorry you do not have permission to view this page."; } else { //Increases the IndexNo by one and defines variables $query = "SELECT IndexNo FROM Links ORDER BY IndexNo DESC LIMIT 1"; $result = mysql_query($query,$link) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $IndexNo = $row['IndexNo']; } $IndexNo = $IndexNo + 1; $Link = $_POST['PageName']; $Data = "BLANK"; //Sets up new query to enter variables into database $query = "INSERT INTO Links VALUES (" . $IndexNo . ", '" . $Link . "');"; mysql_query(query,$link) or die(mysql_error()); $query = "INSERT INTO ExtraContent VALUES (" . $IndexNo . ", '" . $Link . "', '" . $Data . "');"; mysql_query($query,$link) or die(mysql_error()); header('Location: pages.php'); } ?> I know it's something small and easy . . . I'm just not seeing it. Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 7, 2007 Share Posted September 7, 2007 $query = "SELECT `IndexNo` FROM `Links` ORDER BY `IndexNo` DESC LIMIT 1"; Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted September 7, 2007 Author Share Posted September 7, 2007 Nope, that's not it . . . That's a copy and pasted bit of code from another page of mine that works fine but I tried it anyways. Here's the error now: 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 ''Links' ORDER BY 'IndexNo' DESC LIMIT 1' at line 1 Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted September 7, 2007 Author Share Posted September 7, 2007 Anyone else see a problem with the code? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 7, 2007 Share Posted September 7, 2007 Change all instances of die(mysql_error()); to die("Error ". mysql_error(). " with query ". $query); Then you'll be able see exactly the query string that is generating the error - and probably see exactly what needs to be fixed to solve the problem. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted September 7, 2007 Author Share Posted September 7, 2007 good advice . . . advice that you had given me earlier and I had forgotten about. Here's the new code that's having problems: $query = "INSERT INTO Links VALUES (" . $IndexNo . ", '" . $Link . "');"; and here's the error 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 'query' at line 1 with query INSERT INTO Links VALUES (6, 'test'); If I copy and paste that code directly into php my admin . . . it works fine. Am I still missing something obvious? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 7, 2007 Share Posted September 7, 2007 OK, so now we know which query was problematic. That one uses the wrong 'construction' for an insert query. Try a variant - http://www.tizag.com/mysqlTutorial/mysqlinsert.php - identify field names and values. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted September 7, 2007 Author Share Posted September 7, 2007 See . . . that shouldn't matter. There has to be something else causing the problem. I mean I'm looking in my beginning SQL book and it says you can do that. In addition to that . . . I HAVE been doing that. Also, the next query statement works just fine. I'm gonna see if I can't just copy and paste the 2nd one and change the values to get the same effect. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted September 7, 2007 Author Share Posted September 7, 2007 wtf . . . it works fine . . . do you see ANY difference between: $query = "INSERT INTO Links VALUES (" . $IndexNo . ", '" . $Link . "');"; and $query = "INSERT INTO Links VALUES (" . $IndexNo . ", '" . $Link . "');"; ??? I know I sure don't, but it works now! Does anyone see ANY reason why the second one works as opposed to the first? 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.