Page 1 of 4 123 ... LastLast
Results 1 to 10 of 38
  1. #1

    Default Help with my php code


    This is a very simple and very basic php code..
    pero bisag unsaon nako di man jud mo True ang 'if' statement.
    unsay possible problem ani?

    this is a very simple username and password authentication
    ++++++++++++++++++++++++++++++++++++++++++++++++++ +

    <?php
    $con=mysql_connect("localhost", "root", "") or die(mysql_error());
    $db=mysql_select_db("user", $con) or die(mysql_error());


    $user=$_POST['user'];
    $pass=$_POST['pass'];


    $query=('SELECT * FROM USERS WHERE (USERNAME = "$user" and PASSWORD = "$pass")');
    $result=mysql_query($query);


    while($row=mysql_fetch_array($result))


    {
    $username = $row['USERNAME'];
    $password = $row['PASSWORD'];
    }
    if($username==$user and $password == $pass)
    {
    include('home.html');
    }
    else
    {
    echo"FAILED TO LOGIN!";
    }


    ?>

    any thoughts? please help

  2. #2

    Default Re: Help with my php code

    paminaw gud og tarong TS..... basta ang g ingon ni teacher timan-e kong dili true.. false gud na siya....

  3. #3

    Default Re: Help with my php code

    $result=mysql_query($query);

    $count = mysql_num_rows($result);
    if($count == 1){
    // naka sud naka
    }

  4. #4

    Default Re: Help with my php code

    ^ dude I did what you post but...

    +++++++++++++++++++++++++++++++

    <?php
    $con=mysql_connect("localhost", "root", "") or die(mysql_error());
    $db=mysql_select_db("user", $con) or die(mysql_error());


    $user=$_POST['user'];
    $pass=$_POST['pass'];


    $query=('SELECT * FROM USERS WHERE USERNAME = "$user" and PASSWORD = "$pass"') or die(mysql_error());
    $result=mysql_query($query);


    $count = mysql_num_rows($result);
    if($count == 1)
    {
    echo"Success";
    }
    else
    {
    echo"FAILED TO LOGIN!";
    }

    ?>

    this is still not working...

    ang db ani kay naa nay sud username ug password...pero still false gi hapon ang iyang statement...

    ngano kaha ni?

  5. #5

    Default Re: Help with my php code

    $link=mysql_connect("localhost", "root", "");
    if(!$link){
    die("ERROR".mysql_error());
    }
    mysql_select_db("databasename", $link);
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];

    $sql="SELECT * FROM table_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);

    if($count==1){
    header("location:login_success.php");
    }
    else {
    echo "Wrong Username or Password";
    }

    basic codes try daw!

  6. #6

    Default Re: Help with my php code

    kni nga part bai,

    $query=('SELECT * FROM USERS WHERE USERNAME = "$user" and PASSWORD = "$pass"')

    to

    $query=('SELECT * FROM USERS WHERE USERNAME = "'.$user.'" and PASSWORD = "'.$pass.'"')

  7. #7

    Default Re: Help with my php code

    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test\retrieve.php on line 13
    Wrong Username or Password

    error....pero still naka encounter ko ani...bisag ok tanan statements nako...false gi hapong ang statement nako...

    wa jud ko kasabot ug ngano...basic raman unta ni...

    di man sad dako ang nag knowledge nako aning php...first time paman ni nako...
    interesado jud ko makat-on ani...

  8. #8

    Default Re: Help with my php code

    Quote Originally Posted by merinoabs View Post
    kni nga part bai,

    $query=('SELECT * FROM USERS WHERE USERNAME = "$user" and PASSWORD = "$pass"')

    to

    $query=('SELECT * FROM USERS WHERE USERNAME = "'.$user.'" and PASSWORD = "'.$pass.'"')
    dude tried it with the concatenate still the same..

  9. #9

    Default Re: Help with my php code

    Quote Originally Posted by senpai91 View Post
    ^ dude I did what you post but...

    +++++++++++++++++++++++++++++++

    <?php
    $con=mysql_connect("localhost", "root", "") or die(mysql_error());
    $db=mysql_select_db("user", $con) or die(mysql_error());


    $user=$_POST['user'];
    $pass=$_POST['pass'];


    $query=('SELECT * FROM USERS WHERE USERNAME = "$user" and PASSWORD = "$pass"') or die(mysql_error());
    $result=mysql_query($query);


    $count = mysql_num_rows($result);
    if($count == 1)
    {
    echo"Success";
    }
    else
    {
    echo"FAILED TO LOGIN!";
    }

    ?>

    this is still not working...

    ang db ani kay naa nay sud username ug password...pero still false gi hapon ang iyang statement...

    ngano kaha ni?
    based sa akong experience, the Command should be,

    SELECT * FROM USERS WHERE USERNAME = 'username' and PASSWORD = 'password' ;
    on a normal MySQL Query.

    But for PHP Syntax,
    $query=("SELECT * FROM USERS WHERE USERNAME = '$user' and PASSWORD = '$password' ")

    Naa pa na'y "." something, naka limut ko sa right syntax, it's in my laptop and I'm too lazy to open it right now, dugay mag load.

    Problem with count, since wala kaayu restriction siguro imu code, it's better/safe to put,

    COUNT>=1

    Logically, if COUNT==1, but if you have two results, then it will be false

  10. #10
    Elite Member
    Join Date
    Jun 2010
    Gender
    Male
    Posts
    1,018

    Default Re: Help with my php code

    $query=('SELECT * FROM USERS WHERE USERNAME = "$user" and PASSWORD = "$pass"')

    When using single quoted string, there will be no parsing.
    The string will be taken as it is.
    So you are comparing your usernames and passwords to the values "$user" and "$pass" respectively.

  11.    Advertisement

Page 1 of 4 123 ... LastLast

Similar Threads

 
  1. need help with my php code
    By silveroni in forum Programming
    Replies: 3
    Last Post: 10-16-2010, 08:50 AM
  2. help with my samsung phone!!!!!!!!!! samsung d820
    By v2s13 in forum Gizmos & Gadgets (Old)
    Replies: 1
    Last Post: 08-17-2006, 01:24 PM
  3. help with my dial-up connection...
    By kaede in forum Networking & Internet
    Replies: 7
    Last Post: 02-08-2006, 04:24 AM
  4. MOVED: help with my dial-up connection...
    By Visual C# in forum Software & Games (Old)
    Replies: 0
    Last Post: 02-08-2006, 02:09 AM
  5. help with my old tape collection
    By steelwater in forum Music & Radio
    Replies: 3
    Last Post: 10-22-2005, 10:39 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
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top