I am working on making server side validation for a form. Using AJAX, the form sends the value in the input field for 'username' to my php page which then checks to see if this username already exists in the database.
Here is my php code:
$result = mysqli_query($dblink, "SELECT * FROM users WHERE `username` = '$regname'")
or die(mysqli_error($dblink));
echo mysqli_affected_rows($result);
*(At the moment I am doing a simple echo for the mysqli_affected_rows just to see if my MySQL query is working as intended)*
The error I am getting is:
Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, object given in /Users/test/Sites/proj/formvalidate.php on line 20
I am not quite sure what this error is trying to tell me. From what I have Googled "object" is a reference to OOP programming methods, but (as far as I know) I am not using OOP concepts/principles in this particular example? Or did I misinterpret this error message?
Thank you.
Rather than passing $result
in to mysqli_affected_rows
you actually want to pass the DB link (returned by mysqli_connect
) which will give you the number of rows affected by the previous query. See:
http://uk.php.net/mysqli_affected_rows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With