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
https://forums.phpfreaks.com/topic/68347-solved-syntax-error-points-gun-to-head/
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

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.

 

 

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?

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.

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?

Archived

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

×
×
  • 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.