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
4 Réponses
+ 2
Query is fine it means matricnumber 999999qq is not found or matricnumber column is not there
+ 1
Probably there is no record in matricnumber with 999999qq value. Try this: SELECT * FROM studentrecord WHERE matricnumber like '9%'
+ 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 }
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.