Results 1 to 2 of 2

Thread: need help in php

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    need help in php

    Hi,

    i am trying to make a simple script in php.. right now i can add to database to mySql..

    my First code in adding data is here:

    PHP Code:
    <?
    //replace username and password with your mysql name and password
    $conn = mysql_connect("localhost","USERNAME","PASSWORD");

    //select the database
    $db = mysql_select_db("wwwtest_db");

    $username = $_POST["username"];
    $password = $_POST["password"];
    $credits = $_POST["credits"];

    //insert the values
    $result= MYSQL_QUERY("INSERT INTO users (id, username, password, credits)".
    "VALUES ('NULL', '$username', '$password', '$credits')");

    echo "Username and password with credits submitted ok.";
    ?>
    Now, my problem is here when im trying to logon is ok but if i write wrong username and password is not giving error but need answer is this ("username and password is invalid"); ..

    the code is here:

    PHP Code:
    <?
    $conn = mysql_connect("localhost","USERNAME","PASSWORD");
    $db = mysql_select_db("wwwtest_db");

    $username = $_POST["username"];
    $password = $_POST["password"];

    $result = MYSQL_QUERY("SELECT * from users WHERE username='$username'and 

    password='$password'")
    or die ("username and password is invalid");

    $worked = mysql_fetch_array($result);

    $username = $worked[username];
    $password = $worked[password];
    $email = $worked[email];

    if($worked)
    echo "Welcome $user! Your Credit left is $credits"; 
    ?>

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: need help in php

    You need to first ensure that you escape your variables. Second the result returned by mysql_query only returns false if a query fails. A query can succeed and return no results.

    mysql_num_rows() will help you here.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width