Jump to content

[SOLVED] Noob: Very basic php/mysql question (syntax error)


raydeneg

Recommended Posts

Hey everyone and thanks in advance. I just started learning php this week but I do have some experience in other languages, mostly c++ but I have dabbled all over. Anyway I am currently teaching my self php with the assistance of "PHP with MySQL Essential Training" from Lynda.com. So while I assume this code should and does work I must be making an obvious typo some where. I have been trying to debug it for some time but I simply cant come up with a working solution.

 

Here is my error message:

"DB query failedYou 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"

 

And the code it is referring to:

 

	function get_subject_by_id($subject_id)
{
	global $connection;

	echo $subject_id . "<br> ";

	// Method 1 of forming the query
	$query = "SELECT * ";
	$query .= "FROM  subjects ";
	$query .= "WHERE id =" . $subject_id . " ";

	/*
	//Method 2 of forming the query
	$query = "SELECT * 
			FROM subjects 
			WHERE id = {$subject_id} ";		
	*/


	$result_set = mysql_query($query, $connection);
	//print_r (mysql_fetch_array($result_set));
	confirm_query($result_set);
	// REMEMBER:
	//if no rows are returned fetch array will return false
	if ($subject = mysql_fetch_array($result_set))
	{
		return $subject;
	}
	else
	{
		return NULL;
	}
}

 

The code is pretty simple and is simply supposed to figure out which page is called and be able to return the data base information associated with it.

Thanks again if anybody can help me, im pretty lost at this point, not sure where I went wrong

 

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.