On Sun, 12 Jul 2009 15:25:15 -0400 (EDT), "Jason Carson" wrote:
> For anyone reading this thread, here is the final code that I used...
>
> $link = mysqli_connect($hostname, $username, $password, $database);
> $stmt = mysqli_prepare($link, "SELECT * FROM administrators WHERE
> adminusers=?);
> mysqli_stmt_bind_param($stmt, "s", $adminuser);
> mysqli_stmt_execute($stmt);
> mysqli_stmt_store_result($stmt);
> $count = mysqli_stmt_num_rows($stmt);
>
> if($count==1){
> header("location:admin.php");
> } else {
> echo "Failure";
> }
You should always check for errors, so...
/* without actually testing or checking against the manual */
$q = "SELECT * FROM administrators WHERE adminusers=?";
if ( $link = mysqli_connect($hostname, $username, $password, $database)
&& $stmt = mysqli_prepare($link, $q)
&& mysqli_stmt_bind_param($stmt, "s", $adminuser)
&& mysqli_stmt_execute($stmt)
&& mysqli_stmt_store_result($stmt))
{
$count = mysqli_stmt_num_rows($stmt);
} else {
/* Of course, at this point it would be nice to know which
function failed. I don't think there is a neat way to
find that out, and checking every function for errors
would make the code look much much worse than using the
old mysql[i]_query functions. Bleah. */
}
/Nisse
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php