Error in SQL Syntax HELP!!!


Posted on 16th Feb 2014 07:03 pm by admin

I have this page:

Code: <?php

session_start();

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//show scouts characters
$get_scouts = "select * from scouts where username = '".$_SESSION['userName']."'";
$get_scouts_res = mysql_query($get_scouts, $conn) or die(mysql_error());
while ($list_scouts = mysql_fetch_array($get_scouts_res)) {
$identity = ucwords($list_scouts['identity']);
$topic_id = $list_scouts['id'];
echo "<ul class="character_list"><li><a href="fight.php?identity=$identity">$identity</li></ul> ";
}
?>

And it goes to this page:

Code: <?php

session_start();

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//check for required info from the query string
if (!$_GET['identity']) {
header("Location: train_fight.php");
exit;
}

//get derived values

$derived = "select * from derived_values where identity = $_GET[identity]";
$derived_res = mysql_query($derived, $conn) or die(mysql_error());

$display_block = "<ul>";

while ($derived_info = mysql_fetch_array($derived_res)) {
$derived_id = $derived_info['id'];
$derived_identity = $derived_info['identity'];
$derived_health = $derived_info['health'];
$derived_energy = $derived_info['energy'];
$derived_acv1 = $derived_info['acv1'];
$derived_acv2 = $derived_info['acv2'];
$derived_dcv1 = $derived_info['dcv1'];
$derived_dcv2 = $derived_info['dcv2'];
$derived_total_cp = $derived_info['total_cp'];

$display_block .= "<li>$derived_identity</li>";

}

$display_block .= "</ul>";

?>

But I am getting this error:

You have an error in your SQL syntax; check the manual that correspondsto your MySQL server version for the right syntax to use atline 1

What am I doing wrong here? If I change my where statement or take it out, it is displaying the information, but I can't figure out what's wrong with my where statement or where I'm getting my "identity" from. Something's wrong but I can't find it. Can anyone help?

136 Like 33 Dislike
Previous php-forum Next php-forum
Other php-forum

Help With editting and deleting form
Hallo !!

So look at this image :

http://img194.imageshack.us/img194/8272/snapshot5f.pn

How to file_get_contents when login required?
Hello!

I am trying to read data from a page that you have to be logged into to view, I am try

Little problem with form insertion in MySQL, Please help!!!
Hi!,

I'm a little bit new with php and I have a little issue here. I created a webform to ins

Images in email problem
I found this script for sending emails, it works but if the email has <img src="image.jp

Insert Failing.
Hey,
I am making a Sign up page for a website, but the insert query into the Database does not se

Extra fields in main body and php required.
I'm new to PHP so please be gentle. I have a little php script below that works well.
The &quo

images aren't rendering
I'm trying to call a JPG file from within PHP (in an effort to hide the actual JPG folder). The imag

upload image name with extension using php
hi frds..

<input id="file1" type="file" name="file[]" &a

Session login issue
I'm wondering how to fix a problem I'm having with a session-based login system

Say I go to h

How to search for several parameters from objects in a database?
I have a database with lots of information about objects.
Now I would like to search for 4 or 5 p

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash