Single Result From SUM With MySQLi
It’s best if you used an alias for your SUM: SELECT SUM(`field`) as `sum` FROM `table_name` And then, you’ll be able to fetch the result normally by accessing the first result row’s $row[‘sum’].
It’s best if you used an alias for your SUM: SELECT SUM(`field`) as `sum` FROM `table_name` And then, you’ll be able to fetch the result normally by accessing the first result row’s $row[‘sum’].
“When I echo $valid the output is $2y$10$zzZCN7UlukvY2skb3ELVp.4y3Oc7NJTEsFyqdstqYxT” $2y$10$zzZCN7UlukvY2skb3ELVp.4y3Oc7NJTEsFyqdstqYxT the hash is only 50 in length and is invalid/too short and as I said, MySQL will fail silently; error reporting/checking would not have helped here. The password’s column length should be 60 (255 is suggested), so it wasn’t stored correctly originally. You will need to … Read more
I suspect you’re calling the function multiple times. But it calls mysqli_close($conn) at the end, so when you try to use it the next time you get an error, because $conn can’t be used any more. Get rid of that line, and close the connection when the script is all done using MySQL (or don’t … Read more
The mysqli_query() method returns an object resource to your $result variable, not a string. You need to loop it up and then access the records. You just can’t directly use it as your $result variable. while ($row = $result->fetch_assoc()) { echo $row[‘classtype’].”<br>”; }
This is exactly the scenario where mysqli is really awkward. To bind multiple params, you have to pass them all as a variable-length argument list to mysql->bind_param(), but the tricky part is that you have to bind them by reference. References in PHP can be pretty confusing. Here’s an rough example (though I have not … Read more
The mysqli_num_rows() function returns the number of rows in a result set. For insert, update and delete use mysqli_affected_rows
An excellent question. And thank you for moving to prepared statements. It seems that after all those years of struggle, the idea finally is starting to take over. Disclaimer: there will be links to my own site because I am helping people with PHP for 20+ years and got an obsession with writing articles about … Read more
You need to define: $dbc before $code = mysqli_real_escape_string ($dbc, $_GET[‘invite’]); ex: $dbc = mysqli_connect(“localhost”, “my_user”, “my_password”, “world”);
That’s because fetch_assoc is not part of a mysqli_stmt object. fetch_assoc belongs to the mysqli_result class. You can use mysqli_stmt::get_result to first get a result object and then call fetch_assoc: $selectUser = $db->prepare(“SELECT `id`,`password`,`salt` FROM `users` WHERE `username`=?”); $selectUser->bind_param(‘s’, $username); $selectUser->execute(); $result = $selectUser->get_result(); $assoc = $result->fetch_assoc(); Alternatively, you can use bind_result to bind the … Read more
Add more error handling. When the connection fails, mysqli_connect_error() can tell you more details. When preparing the statement fails mysqli_error() has more infos about the error. When executing the statement fails, ask mysqli_stmt_error(). And so on and on… Any time a function/method of the mysqli module returns false to indicate an error, a) handle that … Read more