Web Hosting Talk







View Full Version : PHP query


hostingen
09-27-2005, 10:04 PM
$db = mysql_connect("localhost", "user", "password" );
mysql_select_db("vpanel", $db);

$query = 'select * from clientdb'
."where name ='$userid'"
." and pass='$password'";

$result = mysql_query($query);

$num_rows = mysql_num_rows($result);
echo $num_rows;

if(num_rows> 0){
$HTTP_SESSION_VARS['valid_user'] = $userid;


}



What is wrong with this fragment? I got some warning like :

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

I am using php4

PlanetWebHost
09-27-2005, 10:22 PM
try this....

$query = "select * from clientdb where name = '".$userid."' AND pass = '".$password."'";

fusionrays
09-27-2005, 10:52 PM
In your query string, there is no space between 'clientdb' and 'where'


Try:


$query = 'select * from clientdb '
." where name ='$userid' "
." and pass='$password' ";


Hope that helps.

hiryuu
09-27-2005, 11:01 PM
Check your return codes and use mysql_error to get a report of just what the server didn't like. If a query fails and you don't know why, echo $query so you can see exactly what the script is trying to execute. Battling around in the dark like this just makes the work harder.

rain5017
09-28-2005, 01:02 AM
$db = mysql_connect("localhost", "user", "password" );
mysql_select_db("vpanel", $db);

$query = "select * from clientdb where name ='$userid' and
pass='$password'";

$result = mysql_query($query);

$num_rows = @mysql_num_rows($result);
echo $num_rows;

if(num_rows> 0){
$HTTP_SESSION_VARS['valid_user'] = $userid;


}