www.webdeveloper.com
Results 1 to 4 of 4

Thread: Connecting to a database

  1. #1
    Join Date
    Mar 2013
    Posts
    2

    Connecting to a database

    I am trying to connect to a data base to pull the information down. The database contains thousands of postcodes that advise the user if it is in a flood risk area.

    I have successfully connected to the database but am having trouble pulling the information from the database. If the postcode is not listed it should return - postcode not listed. The code I am using is returning every postcode back saying not listed so I must have an error in my "get details". Any help would be appeciated.

    My php code is
    $postcode = "postcode1";
    $result = mysql_query("SELECT * FROM `TABLE 1` WHERE postcode='$postcode' ")
    or die(mysql_error());


    $row = mysql_fetch_array( $result );
    if(mysql_num_rows($row) >= 1)
    {
    echo "Postcode: ".$row['postcode'];
    echo "Level: ".$row['level'];
    echo "Floodlevel: ".$row['floodlevel'];
    } // display success message

    else { echo "The postcode entered is not listed on the database";
    }

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,518
    In the code posted, this line will make your code always look for "postcode1", which I am guessing is not a valid post code?
    PHP Code:
    $postcode "postcode1"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2013
    Posts
    2

    use of postcode

    I had only used "postcode1" as the search for postcode1 was unlikely from the user? If I use a "real postcode" the output is the same.

  4. #4
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    Bud, you have that $postcode stuck between single quotes.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles