I am posting very simple PHP/mysql as below, to get the hang of creating a DB query, and checking if my syntax, and contruction logic is correct, However when I post the code below:
$dbhost = 'localhost';
$dbuser = 'myuser';
$dbpss = 'myassword';
//connect to database//
$conn = mysql_connect($dbhost, $dbuser, $dbpss) or die('Error connecting to mysql');
$dbname = 'mydb';
mysql_select_db($dbname);
$uname = $_POST['login'];
$pword = $_POST['lpassword'];
$query = 'SELECT id FROM user WHERE username="$uname"';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
echo <br>$num_rows</br>;
I just get the following returned in my browser:
$num_rows
; ?>
(Note; The $uname posted in the form is in the user table 5 times)
And, if I change the code to :
$dbhost = 'localhost';
$dbuser = 'myuser';
$dbpss = 'myassword';
//connect to database//
$conn = mysql_connect($dbhost, $dbuser, $dbpss) or die('Error connecting to mysql');
$dbname = 'mydb';
mysql_select_db($dbname);
$uname = $_POST['login'];
$pword = $_POST['lpassword'];
$query = 'SELECT id FROM user WHERE username="$uname"';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
echo $num_rows;
my browser return is blank
I have run the following command from the Query Browser tool:
SELECT if FROM user WHERE username="martin.thorburn@tiscali.co.uk";
I have done this to ensure I am connecting to the DB correctly, and using the correct DB. I receive 5 results ($uname is martin.thorburn@tiscali.co.uk as entered in my form).
I have also tried different variations of echo, print and die (with error) but the browser return is blank.
I would be grateful if anyone can point me in the right direction?