php help_connecting sql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ma5ect
Forum Commoner
Posts: 35
Joined: Wed Jun 25, 2008 8:38 am

php help_connecting sql database

Post by ma5ect »

Hi,

I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out..

could any1 help..

error:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\checklogin.php on line 18
Wrong Username or Password

code:
<?

$hostname_mysql_connect = "localhost";
$database_mysql_connect = "website_members";
$username_mysql_connect = "root";
$password_mysql_connect = "******";
$tblname_mysql_connect ="members";

$mysql_connect = mysql_pconnect($hostname_mysql_connect, $username_mysql_connect, $password_mysql_connect, $tblname_mysql_connect) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_mysql_connect) or die(mysql_error());

$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];

$sql = "SELECT * FROM $tblname_mysql_connect WHERE username= '$myusername' and password='$mypassword'";
$result = mysql_query($sql);

$count = mysql_num_rows($result); (line 18)
if($count==1) {
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}

?>


many thanx
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php help_connecting sql database

Post by Christopher »

The query ($result = mysql_query($sql);) is failing for some reason. Check for an error after the query and print an error message to find the problem.
(#10850)
ma5ect
Forum Commoner
Posts: 35
Joined: Wed Jun 25, 2008 8:38 am

Re: php help_connecting sql database

Post by ma5ect »

thanx 4da reply. But i have checked da query but cant seem to find da error. Could some1 pleas help..
ma5ect
Forum Commoner
Posts: 35
Joined: Wed Jun 25, 2008 8:38 am

Re: php help_connecting sql database

Post by ma5ect »

Hi,

i changed the code in the query to :
$sql = "SELECT * FROM $tblname_mysql_connect WHERE username= '$myusername' and password='$mypassword'";
$result = mysql_query($sql) or die(mysql_error());

and this message is shown:

Unknown column 'password' in 'where clause'
ma5ect
Forum Commoner
Posts: 35
Joined: Wed Jun 25, 2008 8:38 am

Re: php help_connecting sql database

Post by ma5ect »

ma5ect wrote:Hi,

i changed the code in the query to :
$sql = "SELECT * FROM $tblname_mysql_connect WHERE username= '$myusername' and password='$mypassword'";
$result = mysql_query($sql) or die(mysql_error());

and this message is shown:

Unknown column 'password' in 'where clause'

I just figured it out...i mis spelt the password field..

many thanx for all posts..
Post Reply