phpmysqlmysql-num-rows

SELECT PHP and MySQL not working


I have this code for the select and printing values. mysql_numn_rows returns null :/

<?php
mysql_connect('localhost','root','');
mysql_select_db("db2517");



$username = "Cristoforo";
$query = mysql_query("SELECT * users WHERE username='$username' ");

$numberOfRows = mysql_num_rows($query);
echo "num: $numberOfRows";


?>

Solution

  • Better use mysqli or pdo instead of mysql.here you missed from in your query so your Query should be

    $query = mysql_query("SELECT * from users WHERE username='$username' ");