#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    Howdy,

    This peice of code is working correctly, except when the data entered is not in the database. Instead of getting the "else" statement, I get a "Document Contains No Data" when the data is invalid. I would like to forward users to an error page, or at least a link if there is an error. I do know that it is entirely the if-else syntax, since the sessions work correctly, and if stripped down to just sql it still doesn't go to the else statement

    <?php
    session_start();

    mysql_connect("localhost", "username", "password");
    $query = "SELECT * FROM login WHERE (appno='$appno') AND (building='$building')";
    $result = mysql_db_query("neighborhood", $query);
    if ($result) {
    while ($r = mysql_fetch_array($result)) {

    $appno = $r["appno"];
    $building = $r["building"];
    $entity = $r["entity"];
    session_register( "appno");
    session_register( "password");
    session_register( "entity");
    echo "appno - $appno<br>";
    echo "password - $password<br>";
    echo "entity - $entity";
    }
    } else {
    //echo "Didn't work.";
    Header( "Location: <A HREF="http://127.0.0.1/bldg/lost.php4");" TARGET=_blank>http://127.0.0.1/bldg/lost.php4");</A>
    }
    //mysql_free_result($result);
    ?>

    Ideas?
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    I think your query is not returning any value.


    use the mysql_num_rows() function to find out the return rows.if it is greater than 0 then it should print the values.

    <?php

    if (mysql_num_rows($result)>0){

    while ($r = mysql_fetch_array($result)) {
    $appno = $r["appno"];
    $building = $r["building"];
    $entity = $r["entity"];
    session_register( "appno");
    session_register( "password");
    session_register( "entity");
    echo "appno - $appno<br>";
    echo "password - $password<br>";
    echo "entity - $entity";
    }
    }
    else {
    //echo "Didn't work.";
    Header( "Location: <A HREF="http://127.0.0.1/bldg/lost.php4");" TARGET=_blank>http://127.0.0.1/bldg/lost.php4");</A>
    }

    ?>




    ------------------

    SR -
    shiju.dreamcenter.net

    Web developer from GOD's own country!!!!

Similar Threads

  1. Requesting help on READTEXT statement
    By hdokes in forum MS SQL Development
    Replies: 1
    Last Post: March 19th, 2004, 08:53 AM
  2. Question about the WHERE statement
    By layz d in forum MS SQL Development
    Replies: 5
    Last Post: January 28th, 2004, 11:58 AM
  3. how can i put an IF statement inside a WHILE statement?
    By Jarrett Green in forum Perl Programming
    Replies: 4
    Last Post: December 22nd, 2003, 10:05 PM
  4. Update database/count statement
    By Signuml99 in forum Database Management
    Replies: 2
    Last Post: November 26th, 2003, 01:07 PM
  5. Figuring out parts of a mySQL statement
    By ChibiGuy in forum PHP Development
    Replies: 2
    Last Post: August 18th, 2003, 10:38 PM

IMN logo majestic logo threadwatch logo seochat tools logo