Please help - my head hurts

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 31, 2014 1:15 pm

Sun Apr 13, 2014 2:11 pm

I cant get my code to work, I get the error, what is it I am doing wrong?

"Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\process-7.php on line 23", various web responses suggest its my database access or query that wrong. I have tried the code in php admin and it works, this is the commented out line below.

Code: Select all

	$site_name = "root";
 	$password = "";
 	$database = "blogs";
 	$server = "localhost";
		$Username = $_POST['Name'];
		$Password = $_POST['Password'];
		echo "Entered name: '$Username'<br />";
		echo "Entered Password : '$Password'<br />";
	mysql_connect($server, $site_name, $password) or die("Error connecting to Server: ".mysql_error());
    mysql_select_db($database) or die("Error connecting to database: ".mysql_error());
		$query = "SELECT * FROM 'users' WHERE 'User-Name' = $Username";
		[color=#800040]//SELECT * FROM `users` WHERE `User-Name` = [color=#BF00BF]password[/color]  - this works in SQL
[/color]		echo $query;
		echo (mysql_num_rows($result));
		//if (mysql_num_rows($result) == 1)
			//echo "found one record";
			//echo $result['User-Password'];
			//echo "name entered: {$_POST['Name']}<br />";
   			//echo "password entered: {$_POST['Password']}<br />";
    		//echo "password from database = : {$result['User-Password']}<br />";

php-forum Fan User
php-forum Fan User
Posts: 974
Joined: Mon Oct 01, 2012 12:32 pm

Sun Apr 13, 2014 11:29 pm

first mistake is using mysql_ library. even the manual page for it suggests using mysqli, or even better: PDO. Second mistake, you're not saving a handle to your connection. Most glaringly though, it looks like you're writing a script to grab passwords from your database. Definitely not going to be helping with that. Good luck with the headache at least

New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 31, 2014 1:15 pm

Mon Apr 14, 2014 4:00 am

Thanks, will try, Bizarrely, I have done a lot of programming over the years!!!, Machine code and pascal, and can do a reasonable attempt at HTML, but some parts of php/sql are painful for me, but I will keep trying.

I have aspirations of writing a larger web page, without using the standard web make programs.

So thought I would start with a simple blog.

The blog asks for your username and password once you have registered, that why its accessing password detail.

Will try your suggestion, my big concern is, is the query structure correct noting I am using a variable.

Thanks again

Post Reply