+ Reply to Thread
Results 1 to 5 of 5

Thread: MySQL or PHP problem

  1. #1
    AttackBunnyPro is offline x10Hosting Member AttackBunnyPro is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    26

    MySQL or PHP problem

    I'm attempting to create a login script, but I can't seem to use mysql_num_rows or mysql_fetch_assoc. Here's my script:

    Code:
     
    <?php
    $username=$_POST['username'];
    $password=$_POST['password'];
    if(!$username || !$password){
       header("Location: http://www.attackbunnypro.x10hosting.com/admin/");
    }
    $username = stripslashes($username);
    $password = stripslashes($password);
    $link = mysql_connect("localhost", "username", "password");
    mysql_select_db("database", $link);
    $result = mysql_query("SELECT * FROM table", $link);
    $count = 0;
    while ($line = mysql_fetch_assoc($result)) {
         $count++;
    }
    if($count == 1) {
      //actions
    }
    ?>
    It gives me this warning:
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/abp/public_html/admin/login.php on line 14
    If I use mysql_num_rows() instead, I get a similar error. Other alterations to mysql_num_rows script, but nothing major.

    I looked at phpinfo(), and it has this:
    MySQL Support: Enabled:
    Active Persistent Links 0
    Active Links 0
    Is that the problem? If so, how can I fix it? If not, what am I doing wrong?

  2. #2
    daman371 is offline x10 Sophmore daman371 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Louisiana
    Posts
    130

    Re: MySQL or PHP problem

    Try this. I'll also add in some debugging code.

    Code:
    <?php
    $username=$_POST['username'];
    $password=$_POST['password'];
    if(!$username || !$password){
       header("Location: http://www.attackbunnypro.x10hosting.com/admin/");
    }
    $username = stripslashes($username);
    $password = stripslashes($password);
    mysql_connect("localhost", "username", "password") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());
    $result = mysql_query("SELECT * FROM table") or die(mysql_error());
    $count = 0;
    while ($line = mysql_fetch_assoc($result)) {
         $count++;
    }
    if($count == 1) {
      //actions
    }
    ?>
    Last edited by daman371; 09-10-2008 at 09:22 PM.

  3. #3
    AttackBunnyPro is offline x10Hosting Member AttackBunnyPro is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    26

    Re: MySQL or PHP problem

    Thanks a ton!

  4. #4
    daman371 is offline x10 Sophmore daman371 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Louisiana
    Posts
    130

    Re: MySQL or PHP problem

    You're very welcome. If you don't mind me asking what was the problem? I put the mysql debugging stuff in and took out the mysql link. Mysql links aren't necessary. When you don't use them, the connection is automatically closed.

  5. #5
    AttackBunnyPro is offline x10Hosting Member AttackBunnyPro is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    26

    Re: MySQL or PHP problem

    I'm guessing it was just the link. It worked fine without it.

+ Reply to Thread

Similar Threads

  1. problem with finding my mysql database (PHP)
    By wikiadmin in forum Free Hosting
    Replies: 1
    Last Post: 06-29-2008, 03:48 PM
  2. MYSQL server for PHP login
    By wtvelocity in forum Free Hosting
    Replies: 3
    Last Post: 06-05-2008, 11:22 AM
  3. Problem with PHP support ticket system (Fantastico)
    By Jarryd in forum Free Hosting
    Replies: 4
    Last Post: 03-10-2008, 01:35 AM
  4. PHP issues after Global Crossing problem
    By eliasr in forum Free Hosting
    Replies: 4
    Last Post: 03-07-2008, 02:54 AM
  5. php problem
    By himgar in forum Free Hosting
    Replies: 1
    Last Post: 02-22-2008, 02:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers