PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



Please help newbe with this querry/syntax error!

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General
View previous topic :: View next topic  
Author Message
biker1000



Joined: 14 Oct 2008
Posts: 4

PostPosted: Tue Oct 14, 2008 9:25 pm    Post subject: Please help newbe with this querry/syntax error! Reply with quote

Hi,

I'm trying to use this function-
Code:

function get_subject_by_id($subject_id) {
 global $connection;
 
 $query = "SELECT * ";
 $query .= "FROM subjects ";
 $query .= "WHERE id=" . $subject_id . " ";
 $query .= "LIMIT 1";
 $result_set = mysql_query($query, $connection);
 confirm_query($result_set);
    if ($subect = mysql_fetch_array($result_set)) {
    return $subject; } else {return NULL; }
}

And get error from there in browser :
"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 'LIMIT 1' at line 1".

I'really dont know what that means - this code supposed to be working - but it doesn't.( I checked the manual and syntax seems ok..I'm clueless.

Can anybody see what am I doing wrong?

Thanks

Confused
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 6033
Location: toronto, canada

PostPosted: Tue Oct 14, 2008 10:48 pm    Post subject: Reply with quote

echo out the query and run it thru the gui of your choice and see what it says
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
biker1000



Joined: 14 Oct 2008
Posts: 4

PostPosted: Wed Oct 15, 2008 12:03 am    Post subject: Reply with quote

lostboy wrote:
echo out the query and run it thru the gui of your choice and see what it says


If I change it like this :

function get_subject_by_id($subject_id) {
global $connection;
//$query = "SELECT * FROM subjects WHERE id = {$subject_id}";
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id= {$subject_id} ";
//$query .= "LIMIT 1";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);
if ($subject = mysql_fetch_array($result_set)) {
return $subject; } else {return NULL;}
}

and echo out( by passing return value to external code)
this is what I get in browser:

"Database query failed: 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"

No mater how I tweak it - this is what I get.
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 6033
Location: toronto, canada

PostPosted: Wed Oct 15, 2008 5:14 am    Post subject: Reply with quote

Code:
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id= {$subject_id} ";
$query .= "LIMIT 1";

echo $sql;
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
biker1000



Joined: 14 Oct 2008
Posts: 4

PostPosted: Wed Oct 15, 2008 12:56 pm    Post subject: Reply with quote

lostboy wrote:
Code:
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id= {$subject_id} ";
$query .= "LIMIT 1";

echo $query;


Then I get:

Undefined variable: subject_id in C:\wamp\www\PHP_Sandbox\test_query.php on line 33
SELECT * FROM subjects WHERE id =

But id is a field in table subjects why should I define it as variable?!
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 6033
Location: toronto, canada

PostPosted: Wed Oct 15, 2008 3:53 pm    Post subject: Reply with quote

$Subject_id has no value, its not showing in the query which is likely what the real problem is
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
biker1000



Joined: 14 Oct 2008
Posts: 4

PostPosted: Sat Oct 18, 2008 1:11 pm    Post subject: Reply with quote

lostboy wrote:
$Subject_id has no value, its not showing in the query which is likely what the real problem is


Thanks!
I'll have to go through my code and find out why...
Back to top
View user's profile Send private message
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



PHP Code Examples
 Stream diffrent sizes of images from a single image to save disk space.
 JavaScript dropdown list menu to switch any page.
 Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
 PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
 Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
 Building a Dynamic Form using Javascript and innerHTML. Add form elements in realtime without refreshing the page.
 A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum