[Solved] mysql can not compare data and parse it with php


Hope it helps you, $num = mysql_num_rows($result); instead of $num = $result1->num_rows;

mysql_fetch_object($result) instead of mysql_fetch_object($result1)

<?php
    if (!$x) {
        echo "<script type="text/javascript">document.location.href="https://stackoverflow.com/questions/20008385/index.php";</script>";
    } else {
        $con = mysql_connect('localhost', 'userdb', 'pwd') or die(mysql_error());
        $db = mysql_select_db('dbname', $con) or die(mysql_error());
        $result = mysql_query("SELECT * FROM `users` WHERE `md5pwd` = '". $x ."'");
        $num = mysql_num_rows($result);
        if($num == 0){
            //if not display an error message
            echo "<script> alert('Usuario inexistente');document.location.href="https://stackoverflow.com/questions/20008385/index.php";</script>";
        }else{
            while($row=mysql_fetch_object($result)){
                $userName=$row->username; 
                echo "<script> alert('BIENVENIDO " . $userName . "') </script>";
                echo "[ " . $userName . " ]\n\n";
            }
        }       
    }
?>

Note: mysql_* functions deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.

4

solved mysql can not compare data and parse it with php