Jump to content

[SOLVED] Syntax error :: points gun to head ::


Styles2304

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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.