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";
}
?>

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;

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.