0

WHERE clause in sql query not working

I'm trying to select all the record of a student from the database: "SELECT * FROM studentrecord WHERE matricnumber = '999999qq' " "SELECT * FROM studentrecord " works and return all students in the database but introducing the WHERE clause in the query to return a particular student didn't work

3rd Apr 2020, 4:22 PM
Jamiu Akinyemi
Jamiu Akinyemi - avatar
4 Antworten
+ 2
Query is fine it means matricnumber 999999qq is not found or matricnumber column is not there
3rd Apr 2020, 5:25 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
Probably there is no record in matricnumber with 999999qq value. Try this: SELECT * FROM studentrecord WHERE matricnumber like '9%'
3rd Apr 2020, 5:28 PM
dozule
dozule - avatar
+ 1
Sudarshan Rai 👑 and dozule Thanks for your reply. Really, there's nothing wrong with the query but why is it that the query is not working if I use prepare statement with bind_param(). Like this, Assuming my sql database connection is mysqlcon $param = $_POST['matricnumber']; if ( $stmt = mysqlcon->prepare("SELECT * FROM studentrecord WHERE matricnumber = ?")) { $stmt->bind_param("s",$param); $stmt->execute(); } else{ //echo error message }
3rd Apr 2020, 10:20 PM
Jamiu Akinyemi
Jamiu Akinyemi - avatar
0
I have got it fixed!. Actually I was trying to do some manipulation with the variable and that is what causes the error. Thanks all.
4th Apr 2020, 9:04 AM
Jamiu Akinyemi
Jamiu Akinyemi - avatar