php and mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    #1

    php and mysql

    sir

    its give affected row zero tell me where is error in following code ?

    <?php
    $con = mysql_connect(" localhost","roo t","123456") ;
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db ("my_db", $con);

    $username = “comp”;
    $passwd = “comp”;



    $sql = "SELECT * FROM per
    WHERE user_id = '".$username ."' AND password = '".$passwd." '";

    $r=mysql_query( $sql);


    if (!r)
    {
    die('Error: ' . mysql_error());
    exit();
    }

    echo mysql_num_rows( $r);

    $rs=mysql_num_r ows($r);
    if($rs==0)
    {
    print "wrong";
    exit();
    }
    else{
    print "right";
    //proceed to perform website’s functionality – e.g. present information to the user
    }

    mysql_close($co n)

    ?>


    it will affected row 0 and wrong

    sanjay
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    #2
    hi friend ,


    $sql = "SELECT * FROM per
    WHERE user_id = '".$username ."' AND password = '".$passwd." '";


    if replace its by following


    $sql = "SELECT * FROM per
    WHERE user_id = 'comp' AND password = 'comp' ";



    its gives right


    sanjay

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Read the Posting Guidelines at the top of this forum about showing code in your thread.

      You are using back-ticks when assigning values to userid and password"
      [php]$username = “comp”;
      $passwd = “comp”;[/php]
      You must use quotation marks.

      Ronald :cool:

      Comment

      Working...