so i want to count the number of entries that match the given 'username' and depending on whether its 0 or 1 i want to return true or false. but i'm not sure how. i can't find a mysql_return equivalent in mysqli. the $username is a defined variable in another script file.
<?php
function user_exists($username) {
$query = mysqli_query($connect, "SELECT COUNT('userid') FROM 'users' WHERE 'username' = '$username' ");
return (mysqli_result($query, 0) == 1) ? true : false ;
}
?>
this is where i'll be using the user_exists() function.
<?php
include 'core/init.php';
if (empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) === true || empty($password) === true) {
$errors[] = 'You need to enter a user name and password';
}
else if (user_exists($username) === false) {
$errors[] = "Username not found.";
}
}
?>
i can include the init.php file but it doesn't seem necessary. its just a file that includes and requires a bunch of other files. including the one that has the user_exists() function. This is my connection script also included in the init.php
<?php
$connect_error = "Connection Problem";
$connect = mysqli_connect('localhost', 'root', '', 'people') or die(connect_error);
?>
mysql_return
equivalent in mysql...!? What's that supposed to be?$connect
to yourmysqli_query
, 2) you're open to MySQL injection.