Results 1 to 8 of 8

Thread: If i had hair i'd be pulling it out! HELP!

  1. #1
    Join Date
    Aug 2008
    Location
    phx
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default If i had hair i'd be pulling it out! HELP!

    Hi all,
    I'm pretty new to PHP and i'm stuck.
    I'm trying to query a database full of zip codes by a specific location ID. If the ZIP code entered in the form matches one of the zips associated with the ID i would like it to continue on the next form page. If not, simply say "sorry your zip code not found". Make sense?
    Here's what i have so far:
    PHP Code:
    <?php
    $cxn 
    mysqli_connect("host","username" ,"pass""db");
    $zipEntry $_POST['zip'];
    $query "SELECT ZIP FROM ZipCodes WHERE locationID = '550'";
    $result mysqli_query($cxn,$query)
        or die (
    "Couldnt Execute.");
    $row mysqli_fetch_field($result);

    if ( 
    $zipEntry == $row['ZIP'] )
    {
    (
    go to some pagethis i don't know how to code either)
    }

    {
    echo "Sorry your Zip not found";
    }
    mysqli_close($cxn);
    ?>
    I can get the code to return the first ZIP associated with the locationID, but if i search for any Zips within that location...nothing.

    Thanks for the help!

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    This should work:
    Code:
    <?php
    $cxn = mysqli_connect("host","username" ,"pass", "db");
    $zipEntry = $_POST['zip'];
    $query = "SELECT ZIP FROM ZipCodes WHERE locationID = '550'";
    $result = mysqli_query($cxn,$query)
        or die ("Couldnt Execute.");
    $row = mysqli_fetch_field($result);
    
    if ( $zipEntry == $row['ZIP'] )
    {
    header("Location: url here");
    } else {
    echo "Sorry your Zip not found";
    }
    mysqli_close($cxn);
    ?>
    Jeremy | jfein.net

  3. #3
    Join Date
    Aug 2008
    Location
    phx
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    "Warning: mysqli_query() expects parameter 1 to be mysqli, null given... on line 17
    Couldnt Execute."
    **scratching head**

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Please make sure that this is all your code.
    Jeremy | jfein.net

  5. #5
    Join Date
    Aug 2008
    Location
    phx
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I appreciate the help. Here's everything i have. Now im getting "Couldnt Execute"
    Code:
    <?php
    $cxn = mysqli_connect("host" , "user" ,"pass", "db");
    $zipEntry = $_POST['zip'];
    $query = "SELECT ZIP FROM ZipCodes WHERE locationID = '550'";
    $result = mysqli_query($cxn,$query)
        or die ("Couldnt Execute.");
    $row = mysqli_fetch_assoc($result);
    
    if ( $zipEntry == $row['ZIP'] )
    {
    header("Location: http://www.google.com");
    } else {
    echo "Sorry your Zip not found";
    }
    mysqli_close($cxn);
    ?>

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Make sure that your in the need for assoc, instead of row, or array.
    Jeremy | jfein.net

  7. The Following User Says Thank You to Nile For This Useful Post:

    ump (09-01-2008)

  8. #7
    Join Date
    Aug 2008
    Location
    phx
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help so far! I've got it working however the code only works if i input the first zipcode for the locationID. If i submit any other Zips (even though they're in that location) it comes back as not found. I need it to query all Zips for the locationID.
    Code:
    <?php
    $cxn = mysql_connect("host","user","pass")
     or die ("Cant Connect. Something is broke");
    $db = mysql_select_db( "dbname", $cxn );
    $zipEntry = $_POST['zip'];
    $query = "SELECT ZIP FROM ZipCodes WHERE locationID = '550'";
    $result = mysql_query($query,$cxn)
        or die (mysql_error());
    $row = mysql_fetch_array($result);
    
    if ( $zipEntry == $row['ZIP'] )
    {
    header("Location:http://www.google.com");
    }
    else
    {
    echo "Sorry your Zip not found";
    }
    mysql_close($cxn);
    ?>

  9. #8
    Join Date
    Aug 2008
    Location
    phx
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks to my girl who is a SQL Query nut letting me know im missing an "AND" in my statement. I appreciate the help!!

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
  •