Jump to content

Newbie Syntax help


brian914

Recommended Posts

I have the following and it gives me an error.

 

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($subject = mysql_fetch_array($result_set)) {

return $subject;

} else {

return NULL;

}

}

 

 

If I comment out the following line, it no longer gives me the error. But it also does not do what it needs to  :(

$query .= "WHERE id=" . $subject_id ." ";

 

 

I am getting this from a tutorial, so it seems like I have everything. What am I missing?

 

Thanks a lot for any help!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/
Share on other sites

use

 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($subject = mysql_fetch_array($result_set)) {
      return $subject;   
   } else {
      return NULL;
   }
}

Link to comment
https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/#findComment-609734
Share on other sites

try

 

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

Link to comment
https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/#findComment-609735
Share on other sites

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.