Screed Posted November 21, 2013 Share Posted November 21, 2013 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 More sharing options...
davej Posted November 21, 2013 Share Posted November 21, 2013 query or $query? Link to comment Share on other sites More sharing options...
Ingolme Posted November 21, 2013 Share Posted November 21, 2013 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 More sharing options...
Screed Posted November 22, 2013 Author Share Posted November 22, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now