Jump to content

Not sure if I should post in php or sql


Screed

Recommended Posts

Hi all,

 

I new to the site and was wondering if some one could help me with an Sql script I'm trying to run in a php file.

 

below is the query I have set up to retrieve the courselist_id from a course_list where the gender is male and the courseid = 4

 

running it in phpadmin it gives the correct result.

 

When I try to run in a function in a php file to query my database I get an error that my syntax is incorrect near "AND gender = 'male'

I just cant see it maybe looking at screen to long.

 

query = "SELECT courselist_id ";

query .= "FROM course_list ";

query .= "WHERE courseid = {$courseid} ";

query .= "AND gender = '{$gender}' ";

$result = mysql_query($connection, $query);

 

while ($row = mysql_fetch_array($result)) {

echo courselist_id = $row;

}

 

Can anyone see where I have gone wrong I'll add the full function if required and the exact error if needs be.

$courseid and $gender are passed into function and are set I have checked this.

 

Regards,

Screed.

 

 

 

Link to comment
Share on other sites

Most likely the problem occured at {$courseid}. Check that $courseid has a valid value.

 

I assume that in your original code query actually is $query or it would have given a syntax error rather than a MySQL error.

Link to comment
Share on other sites

Hi Lads,

 

Thanks for your input yes indeed it should have been $query above was a typo, I was writing it from memory and not using my usual computer.

 

Ingolme you were correct the {$courseid} was not be passed so I had to set it into $_SESSION so I could use it.

 

Regards,

Screed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...