mysql_fetch_array and num_rows

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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??/

    #2
    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...
    _______
    Info & Tips
    php.net
    w3schools.com

    Comment


      #3
      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

      Comment


        #4
        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); 

        Comment


          #5
          ok bro am gonna try that!

          Comment


            #6
            PHP Code:
            $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.




            Comment


              #7
              hmm this code is ok.

              PHP Code:
              $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
              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";} 
              i would suggest simply to get a user id from db, without exact match of username.
              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";} 
              Advertise your mobile site for FREE with AdTwirl

              Comment


                #8
                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

                Comment


                  #9
                  ??? 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
                  }

                  Comment


                    #10
                    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...";

                    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ノ刀ノイリ!

                    Comment


                      #11
                      i got it to work thanx any way

                      Comment


                        #12
                        Originally posted by djlee View Post
                        ??? 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
                        }
                        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.




                        Comment

                        Working...
                        X