0

Hallo daniweb!, Im new here *hehe* anyway I've been working on our companys website for a while now but I just cant get it to work... the error is @ the 26:th line.
btw we're using: Cirtex hosting

the defination "myusername" and "mypassword" is in the prev. .php file (main_login.php) this is suppost to check if the account name and password is correct if it is send to succes.php. from there a profile session is comming, but now to this problem!

wanna look on the error you could also go from our main-page
http://test.infernixe.com/portal/checklogin.php

just to mention it works on my localhost with wamp 2.1 ....

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/***/***/checklogin.php on line 26
*dont bother about this Wrong Username or Password*

I would appreciate alot if you helped me!

thanks
- Mattias
here's the code

<?php
$host="localhost"; // Host name 
$username="infernix_root"; // Mysql username 
$password="******"; // Mysql password 
$db_name="infernix_accounts"; // Database name 
$tbl_name="_accounts"; // Table name

// Connect to server and select the databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form in main_login 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

// protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

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

// Mysql_num_row counting table row now
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

Edited by holmiboii: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by holmiboii
1

The problem is that the query fails. Change line 23 to the following:

$result = mysql_query($sql) or die(mysql_error());

If you want to trap any error you can also change line 26 into this:

if ($result)
  $count = mysql_num_rows($result);
else
  $count = 0;
0

The problem is that the query fails. Change line 23 to the following:

$result = mysql_query($sql) or die(mysql_error());

If you want to trap any error you can also change line 26 into this:

if ($result)
  $count = mysql_num_rows($result);
else
  $count = 0;

you are the best! :) thanks alot!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.