Originally posted by djlee
View Post
mysql_fetch_array and num_rows
Collapse
X
-
do you have any links with this sorrt of optimisation and validation help. as i wna take validation to an extra level. what i learnt so foar of my own back is ok but wna take it that little further.
-
would this be any good?
(i've posted this in wrong thread before lol)
PHP Code:$check = mysql_query("SELECT name FROM members WHERE name = '$nm'") or die(mysql_error());
$checkresult = mysql_num_rows($check);
if($checkresult != 0)
{
echo "Sorry $username is already in use ! <a href=\"link_to_registration.php\">Choose another username</a>";
}
else
{
echo "bla bla...";
}
Leave a comment:
-
??? you dont need a function, any errors that stem from the fetch_assoc, array, num_rows functions are due to bad php structure, validation and sanitisation. Your specific error however i cant say why your original code wasnt working, even with no data in the variable it should still run the query but look for a empty field and return no records and fetch array would simply be bool false. If i had lavalair or whatever code your using and your problem script i could probably figure it out, you might wanna learn some basic debug stuff too, such as mysql_error() and printing out the query so you can see what its trying to run with your sample data.
as for your code it would be better in regards to optimisation if you ran the check like so (this suggests you are only checking for registered members under the given name and will not actually use any positive resultsets later on)
Code:if((int)mysql_result(mysql_query("SELECT id FROM members WHERE name LIKE '".mysql_real_escape_string($nm)."' LIMIT 1"),0) > 0) { //username is registered } else { //username is not regged }
Leave a comment:
-
do u thinl i should create sum kind of function for this mysql_fetch_array() thats the error poping up and that code looks like a function
Leave a comment:
-
hmm this code is ok.
And brumis code, check is array.PHP Code:$check = mysql_fetch_array(mysql_query("SELECT count(*) FROM members WHERE name='".$nm."'"));
if ($check[0]>0) echo 'username is registered';
you can do it this way if you select a string from db
i would suggest simply to get a user id from db, without exact match of username.PHP Code:$check = mysql_fetch_array(mysql_query("SELECT name FROM members WHERE name='".$nm."'"));
if(isset($check[0][1])){echo "sorry this username is already taken";}
PHP Code:$check = mysql_fetch_row(mysql_query("SELECT id FROM members WHERE name LIKE '".mysql_real_escape_string($nm)."' LIMIT 1"));
if($check[0]>0){echo "sorry this username is already taken";}
Leave a comment:
-
make sure that $nm has soemthing assigned to itPHP Code:$check = mysql_fetch_array(mysql_query("SELECT name FROM members WHERE name='".$nm."'"));
if($check>0){echo "sorry this username is already taken";}
Leave a comment:
-
my guess remove the count and the brackets around the *
try
PHP Code:$query = sprintf("SELECT * FROM members where name ='".$nm."'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
Leave a comment:
-
hey bro this is wats at that line.....
$check = mysql_fetch_array(mysql_query("SELECT count(*) FROM members WHERE name='".$nm."'"));
this code is to check if username is already registered
Leave a comment:
-
mysql_fetch_array and num_rows
when i have those in my codings i get errors like this
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/sitename/file.php on line 54
y is that??/Tags: None
Leave a comment: