Activity Stream
48,167 MEMBERS
61738 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 9 of 9
  1.     
    #1
    Member
    Website's:
    SourceParadise.com MobileMaster.org

    Default Help With PHP Error

    Hi guys,
    I`m learning PHP with MySQL and have some problem.

    I`m just creating a simple script to accept login details from index.php and transfer them to login.php via POST. 1st part went smooth. For 2nd part, login.php I`m having some problem.

    I tried google and change the variable names too but the result was same. I kept getting error:
    Code: 
    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\login.php on line 10
    My login.php is here:
    PHP Code: 
    <?php
    $con
    mysql_connect("localhost","usermaster","") or die (mysql_error());
    $cName$_POST["boxuser"];
    $cPass=$_POST["boxpass"];
    mysql_select_db("mynewdb");
    //$data = "select * from mytable where uname=".$cName."and upass=".$cPass;
    $query "SELECT * FROM mytable";
    $result mysql_query($query);
    $row mysql_fetch_array($result);

    if ((
    strlen($row))>0)
    {
        echo 
    "Login successful.";
    }
    else
    {
        echo 
    "Login failed.";
    }
    mysql_close();
    ?>
    Can anyone help me ?
    nEw_boY Reviewed by nEw_boY on . Help With PHP Error Hi guys, I`m learning PHP with MySQL and have some problem. I`m just creating a simple script to accept login details from index.php and transfer them to login.php via POST. 1st part went smooth. For 2nd part, login.php I`m having some problem. I tried google and change the variable names too but the result was same. I kept getting error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\login.php on line 10 My login.php is here: <?php Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Respected Member
    Website's:
    DL4Everything.com Soft2050.in
    mysql_fetch_array - Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
    http://php.net/manual/en/function.mysql-fetch-array.php

    Use mysql_num_rows to check whether the query returned any results or not:
    http://php.net/manual/en/function.mysql-num-rows.php

    PHP Code: 
    <?php

    if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access

    $conmysql_connect("localhost","usermaster","") or die (mysql_error());
    $cNamemysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
    $cPassmysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
    mysql_select_db("mynewdb");
    //$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
    $query "SELECT * FROM mytable WHERE uname=$cName and upass=$cPass";
    $result mysql_query($query);
    $row mysql_num_rows($result);

    if (
    $row 0)
    {
        echo 
    "Login successful.";
    }
    else
    {
        echo 
    "Login failed.";
    }
    mysql_close();

    } else {

        die(
    'RETRY AGAIN FROM THE LOGIN PAGE');

    }

    ?>
    Use php's mysql_real_escape_string to prevent from mysql injections attacks - http://www.php.net/manual/en/functio...ape-string.php

  4.     
    #3
    Member
    Website's:
    SourceParadise.com MobileMaster.org


    Its the same error as before. Is there any problem with my config ?
    Anything you can guess ?

  5.     
    #4
    Respected Member
    Website's:
    DL4Everything.com Soft2050.in
    Ahh f**k! Yeah its similar
    You need to also specify the connection in mysql query

    Try this! Should work:
    PHP Code: 
    <?php

    if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access

    $conmysql_connect("localhost","usermaster","") or die (mysql_error());
    $cNamemysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
    $cPassmysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
    mysql_select_db("mynewdb"$con);
    //$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
    $query "SELECT * FROM mytable WHERE uname=$cName and upass=$cPass";
    $result mysql_query($query$con);
    $row mysql_num_rows($result);

    if (
    $row 0)
    {
        echo 
    "Login successful.";
    }
    else
    {
        echo 
    "Login failed.";
    }
    mysql_close();

    } else {

        die(
    'RETRY AGAIN FROM THE LOGIN PAGE');

    }

    ?>
    Also fixed for mysql_select_db which also requires connection to be specified

  6.     
    #5
    Member
    Website's:
    SourceParadise.com MobileMaster.org
    Nope, its the same.
    I tried to fix it for almost 12 hrs yesterday but it aint worked.
    Let me grab some tutorial script and confirm that my config is okay.

    Fix it meanwhile, if anything seems wrong.
    Edit:
    My connection is doing good, tried pre-made script, can someone point out the error please ?

  7.     
    #6
    Respected Member
    Website's:
    DL4Everything.com Soft2050.in
    Found it and tested too! it does works now

    PHP Code: 
    <?php

    if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access

    $conmysql_connect("localhost","usermaster","") or die (mysql_error());
    $cNamemysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
    $cPassmysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
    mysql_select_db("mynewdb"$con);
    //$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
    $query "SELECT * FROM mytable WHERE uname='$cName' and upass='$cPass'";
    $result mysql_query($query$con);
    $row mysql_num_rows($result);

    if (
    $row 0)
    {
        echo 
    "Login successful.";
    }
    else
    {
        echo 
    "Login failed.";
    }
    mysql_close();

    } else {

        die(
    'RETRY AGAIN FROM THE LOGIN PAGE');

    }

    ?>
    The problem was in sql query where the value to check was directly given which was making query take it as unique column.

  8.     
    #7
    Member
    Website's:
    SourceParadise.com MobileMaster.org
    I still have the same problem.
    I even tried just plain SELECT * from mytable but it isnt working. fetch_array or num_rows, none of them are working.

    Are you sure that you tried it ? Can anyone else confirm it ?

  9.     
    #8
    Respected Member
    Website's:
    DL4Everything.com Soft2050.in
    Yes i tried it. Here's my try code:
    PHP Code: 
    <?php

    //if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access

    $conmysql_connect("localhost","username""") or die (mysql_error());
    $cName'admin'//mysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
    $cPass'mymd5hashedtestpass'//mysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
    mysql_select_db("dle"$con);
    //$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
    $query "SELECT * FROM dle_users WHERE name='$cName' and password='$cPass'";
    $result mysql_query($query$con) or die (mysql_error());
    $row mysql_num_rows($result);

    if (
    $row 0)
    {
        echo 
    "Login successful.";
    }
    else
    {
        echo 
    "Login failed.";
    }
    mysql_close();

    //} else {

      //  die('RETRY AGAIN FROM THE LOGIN PAGE');

    //}

    ?>
    I only removed checks and added user & pass (md5) hash! Not sure why the code didn't works for you though

    Edit: I am pretty much sure that the problem is in your query so make it output the error:
    PHP Code: 
    <?php

    if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access

    $conmysql_connect("localhost","usermaster","") or die (mysql_error());
    $cNamemysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
    $cPassmysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
    mysql_select_db("mynewdb"$con);
    //$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
    $query "SELECT * FROM mytable WHERE uname='$cName' and upass='$cPass'";
    $result mysql_query($query$con) or die (mysql_error());
    $row mysql_num_rows($result);

    if (
    $row 0)
    {
        echo 
    "Login successful.";
    }
    else
    {
        echo 
    "Login failed.";
    }
    mysql_close();

    } else {

        die(
    'RETRY AGAIN FROM THE LOGIN PAGE');

    }

    ?>

  10.     
    #9
    Member
    Website's:
    SourceParadise.com MobileMaster.org
    Oh man, I cant thank you in words...
    You really solved it.

    The query returned false error that PHP considered as Boolean, your last code was right but I forgot to update the column names of my database. Its done, solved.

    Tons of love to you, brother.
    Solved.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Error Detected in sitemap XML. How to remove error?
    By Bobby3711 in forum Web Application/Script Support
    Replies: 1
    Last Post: 21st Mar 2012, 03:51 PM
  2. Rapidleech error: Error openning rar process
    By tractor3231 in forum Server Management
    Replies: 13
    Last Post: 14th Dec 2011, 04:35 AM
  3. HTTP Error 500 (Internal Server Error):
    By joshmoore in forum Technical Help Desk Support
    Replies: 4
    Last Post: 25th Nov 2011, 03:59 AM
  4. wtf happened? (ipb 3.23 skin error causes fatal error)
    By mrHunt in forum Technical Help Desk Support
    Replies: 1
    Last Post: 25th Nov 2011, 03:55 AM
  5. Adding Domain Error in cPanel (Error from park wrapper:)
    By Ryza in forum General Discussion
    Replies: 0
    Last Post: 20th Feb 2011, 01:57 AM

Tags for this Thread

BE SOCIAL