0

The sql runs perfectly in mysql, but when entered in a query in php, it genetrates a HTTP 500, not sure why?

$sel_query="SELECT 
    Class_List.Class_List_id,
    Class_List.class_id, 
    count(Class_List.user_id) 
  AS 
    Total,
    User_Accounts_.user_id, 
    User_Accounts_.firstname, 
    User_Accounts_.lastname, 
    User_Accounts_.ALN, 
    User_Accounts_.EAL, 
    count(if(User_Accounts_.Gender="Male",1,NULL)) 'Male', 
    count(if(User_Accounts_.Gender="Female",1,NULL)) 'Female', 
    count(if(User_Accounts_.Gender="ALN",1,NULL)) 'ALN', 
    count(if(User_Accounts_.Gender="EAL",1,NULL)) 'EAL' 
FROM Class_List, User_Accounts_ 
WHERE User_Accounts_.user_id=Class_List.user_id AND Class_List.class_id=1";
3
  • "Male" , "Female" , "ALN" , "EAL" ... instead of double quote use single quote Commented Dec 3, 2021 at 10:13
  • Hello, I was edit to make your SQL more readable. No syntax change just add new line and indent to be more easy to read. Commented Dec 3, 2021 at 10:17
  • Shirshaks comment tells you the solution, however I would advise you to take a look at the error log file and try to understand the error. In this case you open the string with double quotes, and use double quotes in the string. You need to escape the double quotes or use single quotes. Commented Dec 3, 2021 at 10:20

1 Answer 1

1

Escape quotes.

$sel_query="
SELECT Class_List.Class_List_id,Class_List.class_id, count(Class_List.user_id) AS Total,User_Accounts_.user_id, User_Accounts_.firstname, User_Accounts_.lastname, User_Accounts_.ALN, User_Accounts_.EAL, count(if(User_Accounts_.Gender=\"Male\",1,NULL)) 'Male', count(if(User_Accounts_.Gender=\"Female\",1,NULL)) 'Female', count(if(User_Accounts_.Gender=\"ALN\",1,NULL)) 'ALN', count(if(User_Accounts_.Gender=\"EAL\",1,NULL)) 'EAL' 
FROM Class_List, User_Accounts_ 
WHERE User_Accounts_.user_id=Class_List.user_id AND Class_List.class_id=1
";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.