Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 38
  1. #11

    Default Re: Help with my php code


    k,
    post daw ng source code sa retrieve.php.

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

    Default Re: Help with my php code

    try daw ni...from boang's codes and stuff I just remembered.

    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'";
    //Added the connection parameter, since you are using procedural. Try the OOP approach if it fits your style.
    $result=mysql_query($link, $sql);
    //You are getting a null or boolean value from $result because during the query the resource object was not supplied
    //which in this case is the connection or link
    $count=mysql_num_rows($result);
    
    if($count>0){
    echo "Success";
    }
    else {
    echo "Wrong Username or Password";
    }
    Kung naa nay debug bay...try checking when nag-null or false ang result.
    Last edited by Klave; 01-26-2012 at 09:35 PM.

  3. #13

    Default Re: Help with my php code

    Quote Originally Posted by Klave View Post
    $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.
    Noted. I'm still reviewing my PHP.

    btw,

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

    ang kaning bold letters (parenthesis)? gamit ba ni? mura'g mao ni siguro naka error?

  4. #14

    Default Re: Help with my php code

    <?php
    $link=mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("user", $link) or die(mysql_error());
    $myusername=$_POST['user'];
    $mypassword=$_POST['pass'];

    $sql=("SELECT * FROM USERS WHERE username='$myusername' and password='$mypassword'") or die(mysql_error());
    $result=mysql_query($sql);
    while($row=mysql_num_rows($result))
    {
    $user=$row['USERNAME'];
    $pass=$row['PASSWORD'];
    {
    if((strcmp($user,$myusername)) and (strcmp($pass,$mypassword)))
    {
    header('Location:home.html');
    }
    else
    {
    echo"FAILED TO LOGIN!";
    }
    }
    }
    ?>

    i altered my code and the local server responded slowly....kung akong i false di li mo echo...kung true mau kay mo sud sa header location...pero loading pud lagi kau...ok ra ang code nako? well for basics anyway

  5. #15

    Default Re: Help with my php code

    Quote Originally Posted by senpai91 View Post
    <?php
    $link=mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("user", $link) or die(mysql_error());
    $myusername=$_POST['user'];
    $mypassword=$_POST['pass'];

    $sql=("SELECT * FROM USERS WHERE username='$myusername' and password='$mypassword'") or die(mysql_error());
    $result=mysql_query($sql);
    while($row=mysql_fetch_array($result))
    {
    $user=$row['USERNAME'];
    $pass=$row['PASSWORD'];
    {
    if((strcmp($user,$myusername)) and (strcmp($pass,$mypassword)))
    {
    header('Location:home.html');
    }
    else
    {
    echo"FAILED TO LOGIN!";
    }
    }
    }
    ?>

    i altered my code and the local server responded slowly....kung akong i false di li mo echo...kung true mau kay mo sud sa header location...pero loading pud lagi kau...ok ra ang code nako? well for basics anyway
    changed to fetch array because the previous seems illogical....and still not working..crap with this man....
    Last edited by senpai91; 01-26-2012 at 09:49 PM.

  6. #16

    Default Re: Help with my php code

    Quote Originally Posted by merinoabs View Post
    k,
    post daw ng source code sa retrieve.php.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form action = "retrieve.php" method="POST">
    USERNAME<input type="text" name="user">
    PASSWORD<input type="password" name="pass">
    <input type="submit" name="submit">
    </form>
    </body>
    </html>

  7. #17

    Default Re: Help with my php code

    kung null kay blank php...

    pero kung true or false....kay false permi ang statement....di jud ma true....

  8. #18

    Default Re: Help with my php code

    ok nana bai sa kni nlng na part.

    if((strcmp($user,$myusername)) and (strcmp($pass,$mypassword)))

    to

    if(strcmp($user,$myusername) == 0 AND strcmp($pass,$mypassword) == 0)

  9. #19

    Default Re: Help with my php code

    ^dude

    if(strcmp($user,$myusername) == 0 AND strcmp($pass,$mypassword) == 0)

    //if($myusername==$user and $mypassword==$pass)

    the above not comment code is yours and tried it works if the statement is true...pero kung false or null a blank php dili mo echo ang naa sa else

    the comment there is mine same thing kung true mo work pero kung null or false no luck...

  10. #20

    Default Re: Help with my php code

    gi simplify lng nko bro.
    nabantayn sd nko nga double checking n cya so ako nlng gipa mub.an


    //Connect to database
    $link = mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("user", $link) or die(mysql_error());

    //Get post parameters from form
    $myusername=$_POST['user'];
    $mypassword=$_POST['pass'];

    //Check database if username & password exist
    $sql = ("SELECT * FROM USERS WHERE username='$myusername' and password='$mypassword'") or die(mysql_error());
    $result = mysql_query($sql);


    if(mysql_num_rows($result) > 0)
    header('Location:home.html');
    else
    echo"FAILED TO LOGIN!";

    gamit 'mysql_real_escape_string' sa mga global variables kng production use ni cya pra ma prevent sa SQL Injection.

  11.    Advertisement

Page 2 of 4 FirstFirst 1234 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