SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php code problem

    i have a problem in this code , this code must check the users in the db first then if the user does not exist it will make a record in the db and if the user exist it will return back Username is already in use , my problem is that every time i enter a user name even it is in the db it makes a new user with the same username

    PHP Code:
    $sql mysql_query("SELECT * FROM login");
    $flag=0;
    while (
    $r mysql_fetch_array($sql)) 

    if (
    $r['user'] == $_POST['user']) 
    {
    $flag=1;
    //searching for the user ib the db
    echo '<font color="#FF0000">';
    echo 
    "* Username is already in use";
    echo 
    '</font>';
    echo 
    "<br>";
    }
    else 
    {
    //entering the job seeker data in the user table
    $sql="INSERT INTO user (name, Addr, Nation, dob, Gen, cnt, mar, mil, phone, mobile, mail, user)
    VALUES
    ('
    $fn','$_POST[add]','$_POST[nat]','$dob','$_POST[gg]','$_POST[cnt]','$_POST[Mar]','$_POST[Mil]','$_POST[ph]','$_POST[mo]','$_POST[mail]','$_POST[user]')";
    //entering the user and pass in the login table
    $sql2="INSERT INTO login (user, pass, type)
    VALUES
    ('
    $_POST[user]','$_POST[pass]','$_POST[type]')";
    if (!
    mysql_query($sql,$con))
        {
        die(
    'Error: ' mysql_error());
        }
        echo 
    "<br>";
    if (!
    mysql_query($sql2,$con))
        {
        die(
    'Error: ' mysql_error());
        }
        echo 
    "<br>";
    echo 
    "<br>Thanks for registration $fn ";
    exit();


  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $flag 0;

    $query "SELECT * FROM login where user ='" $_POST['user']. "'";
    $result $sql mysql_query$query );

    if ( 
    $result ) {
        
    $flag=1;
        echo 
    '<font color="#FF0000">';
        echo 
    "* Username is already in use";
        echo 
    '</font>';
        echo 
    "<br>";
    } else {

    // Do your inserts here


    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that results that it prints already in use even when the db is empty

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do a var_dump on $result and tell me what it outputs.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    write me the syntex

  6. #6
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    plz

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query "SELECT * FROM login where user ='" $_POST['user']. "'";
    echo 
    $query// Lets take a look @ your actual query

    $result $sql mysql_query$query );
    var_dump$result ); // Lets take a look@ your returned resultset 
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  8. #8
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the result of echo $query
    SELECT * FROM login where user ='mariam'
    and this is the result of the var_dump
    resource(2) of type (mysql result)

  9. #9
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result $sql mysql_query$query );
    var_dump$result ); // Lets take a look@ your returned resultset 

    while ( $r mysql_fetch_assoc$result ) { // lets see whats in these two results
        
    var_dump$r );

    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  10. #10
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    error in that line
    while ( $r = mysql_fetch_assoc( $result )
    error message
    Parse error: parse error in

  11. #11
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    while ( $r mysql_fetch_assoc$result )) { // lets see whats in these two results
        
    var_dump$r );

    Sorry I left out a closing )
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  12. #12
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it results SELECT * FROM login where user ='mariam'
    & resource(2) of type (mysql result)

  13. #13
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result mysql_query$query );
    var_dump$result ); // Lets take a look@ your returned resultset 

    while ( $r mysql_fetch_assoc$result ) { // lets see whats in these two results
        
    var_dump$r );

    Einstein try this one more time. the problem was in "$result = $sql = "
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.


Bookmarks

Posting Permissions

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