The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Error

Discussion in 'General Discussion' started by sebbyw, Feb 14, 2014.

  1. sebbyw

    sebbyw Registered

    Joined:
    Feb 14, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hello everyone. I just want to say I am very new to cpanel forums. I know html, a bit of php and css. Now I took some code from here to make a php form: /http://www.phpeasystep.com/phptu/6.html I took all of the code from there and made some tweaks to try and fix this error. When I uploaded it to my cpanel file manager I tested to see if it works and got this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/sebbyw/public_html/checklogin.php on line 27
    Wrong Username or Password

    Here is the code in my checklogin.php:

    Code:
    <?php
    
    ob_start();
    $host="localhost"; // Host name 
    $username="sebbyw_root"; // Mysql username 
    $password="password123"; // Mysql password 
    $db_name="sebbyw_test"; // Database name 
    $tbl_name="sebbyw_members"; // Table name 
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // Define $myusername and $mypassword 
    $myusername=$_POST['myusername']; 
    $mypassword=$_POST['mypassword']; 
    
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result = mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows ($result);
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){
    
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword"); 
    header("location:login_success.php");
    }
    else {
    echo "Wrong Username or Password";
    }
    ob_end_flush();
    ?>
    Can someone please help me to fix it. Thank you very much. Also, I have not made a "Registration" page yet.
    If you need more info to help find the bug please just ask. The site: - Removed -
     
    #1 sebbyw, Feb 14, 2014
    Last edited by a moderator: Feb 15, 2014
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,460
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Are you having some sort of issue with your cPanel?
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,743
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    You will likely receive more assistance with developing a PHP script at forum that specializes in PHP or web design. These forums are primarily intended for issues related to the cPanel software itself. You may want to try making sure the database user is added to the database, or re-create the MySQL username with the password you have entered in your script configuration to make sure there were no typing mistakes.

    Thank you.
     
Loading...

Share This Page