mysql_fetch_array and num_rows
Started on the old forum in January 2010 · view the original in the archive · old links redirect here
Cant find sql bro your missing a sql or wrong val for sql.
Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!
SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…
$check = mysql_fetch_array(mysql_query("SELECT name FROM members WHERE name='".$nm."'"));
if($check>0){echo "sorry this username is already taken";}
make sure that $nm has soemthing assigned to it
Want something coded email me at sales@webnwaphost.com for a prices.
hmm this code is ok.
$check = mysql_fetch_array(mysql_query("SELECT count(*) FROM members WHERE name='".$nm."'"));
if ($check[0]>0) echo 'username is registered';
And brumis code, check is array. you can do it this way if you select a string from db
$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";}
i would suggest simply to get a user id from db, without exact match of username.
$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";}
Advertise your mobile site for FREE with AdTwirl
??? 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)
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
}
would this be any good? (i've posted this in wrong thread before lol)
$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...";
}
It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.
キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!
djlee wrote: ??? 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)
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 }
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.
Want something coded email me at sales@webnwaphost.com for a prices.