alright i don't know if i can just copy and paste the code here but its worth a try...
global $default_dbname, $user_tablename;
$link_id = db_connect($default_dbname);
$query = "SELECT username FROM $user_tablename
WHERE userid = '$userid'
AND userpassword = password('$userpassword')";
$result = mysql_query($query);
if(!result) die(sql_error(error_message()));
if(!mysql_num_rows($result)) return 0;
else {
$query_data = mysql_fetch_row($result);
return $query_data[0];
}
For the line that states if(!mysql_num_rows($result)) return 0; I get the error stating that the argument sent is not a valid argument of that function.
Does anyone know how to fix this? I am stumped.
~Akwebby
PHP Question
Moderator: General Moderators
If you're looking to end script execution in the if statement try this:
Code: Select all
<?php
if (!mysql_num_rows($result)) {
die("No result found.");
}
?>1.
2.
Just some thoughts as I never write like this myself:
In this example, that else-statement... what IF-statement does that belong to really, when you ignore using {}'s in your code?
3.
Akwebby
Friendly note and advice... Use {}'s and indents. It will help you later on in your phpcoding life.
Code: Select all
<?php
if(!result) die(sql_error(error_message())); // this is wrong in your script
if(!$result) die(sql_error(error_message())); //...as youre missing the $
?>Just some thoughts as I never write like this myself:
Code: Select all
if(!$result) die(sql_error(error_message()));
if(!mysql_num_rows($result)) return 0;
else {
$query_data = mysql_fetch_row($result);
return $query_data[0];
}3.
Akwebby
Friendly note and advice... Use {}'s and indents. It will help you later on in your phpcoding life.
Code: Select all
// just example of one way to write code...
if (!$result) {
die(sql_error(error_message()));
}
if (!mysql_num_rows($result)) {
return 0;
} else {
$query_data = mysql_fetch_row($result);
return $query_data[0];
}Alright the copy and paste really screwed up readability before so here it is again...
global $default_dbname, $user_tablename2;
$link_id = db_connect($default_dbname);
$query = "SELECT username FROM $user_tablename2 WHERE userid = '$userid' AND userpassword = password('$userpassword')";
$result = mysql_query($query);
if(!$result) die(sql_error(error_message()));
if(!mysql_num_rows($result)) return 0;
else
{
$query_data = mysql_fetch_row($result);
return $query_data[0];
}
The emboldened line is where my question lies. I get an error stating that the supplied argument is not valid for the called function, but it most certainly is valid in my mind. Any thoughts?
global $default_dbname, $user_tablename2;
$link_id = db_connect($default_dbname);
$query = "SELECT username FROM $user_tablename2 WHERE userid = '$userid' AND userpassword = password('$userpassword')";
$result = mysql_query($query);
if(!$result) die(sql_error(error_message()));
if(!mysql_num_rows($result)) return 0;
else
{
$query_data = mysql_fetch_row($result);
return $query_data[0];
}
The emboldened line is where my question lies. I get an error stating that the supplied argument is not valid for the called function, but it most certainly is valid in my mind. Any thoughts?