So, I have some code. I know that mysql_num_rows is deprecated, but since I've already used it I don't want to switch everything to mysqli_. Anyway it was working on my local server and returning 1 or more results based on the entry. This is a PHP login script that I'm trying to get to work. When I uploaded the script to my hostgator server it didn't work. I also checked the PHP version and it mysql_num_rows() shouldn't be deprecated in version 5.4.xxx.
When I try doing a test query of just SELECT * FROM customers it returns one row, but it's not returning anything when I search for where the user and password equal the posted variables. It's frustrating me, and I could use a second set of eyes to look at this.
<?php
include('mysql_connect.php');
if(isset($_POST['submit'])) {
if(isset($_POST['cususername']) AND isset($_POST['cuspassword'])) {
$username = $_POST['cususername'];
$password = md5($_POST['cuspassword']);
$query = "SELECT * FROM customers WHERE username = '" . $username . "' AND
password = '" . $password . "'";
$returned_user = mysql_query($query);
$number_of_users = mysql_num_rows($returned_user);
if($number_of_users > 0){
echo "It got this far!";
$customer_array = mysql_fetch_array($returned_user);
$_SESSION['user_logged'] = 1;
$_SESSION['id'] = $customer_array['customer_id'];
$_SESSION['user_name'] = $customer_array['username'];
}
}
}
?>
<?php
if(isset($_REQUEST['loggoff'])) {
unset($_SESSION['user_logged']);
unset($logged_status);
}
if(isset($_SESSION['user_logged'])) {
$logged_status = $_SESSION['user_logged'];
}
if(isset($logged_status)) {
if($logged_status == 1) {
echo "You are logged in as " . $_SESSION['user_name'] . ", Click here to <a href='" . $_SERVER['PHP_SELF'] . "?loggoff=1'>Log off</a>" . "<br>";
}
}
else {?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="customerlogin">
<input type="text" name="cususername" id="cususername" />
<input type="password" name="cuspassword" id="cuspassword" />
<br />
<input type="submit" name="submit" value="Login" />
</form>
<?php}?>