SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Clay County, Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want a form where users can enter in their address. The Form will have 7 input fields number,direction,name,type,post_dir,citycode,zipcode with all being optional except name and zipcode. direction, type, post_dir,and citycode being dropdown. This form will submit a query to a table called vrstrt with fields of citycode, direction, name, type, post_dir, lo_range, hi_range, odd_even, precinct, grp,zipcode, and business. The query will need to make sure that the number input field on the forms submit is equal to or greater than the lo_range and less than or equal to the hi_range for that record and will then result and print display on the page the data within the precinct field for that record. I do not expect or desire the code for this task. I am new to php and just want to know if there are any resources available to find the answer or method to my project. I just need to know where to start.

  2. #2
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I presume, by table, you mean MySQL table correct? If so then, this wont be very difficult.

    How new are you to PHP? What you need done can be done by simple php coding. The only complicated part would be the Mysql query. Nothing other then that. A good place to start your research on would be phpbuilder.com.
    i dunno...

  3. #3
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Clay County, Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, It is a MySQL database. How New? Well let's just say I am awaiting the mail to deliver a couple of books and have finished a couple of online tutorials. I believe the SQL Statement would be $sql = "SELECT * FROM vrstrt WHERE (hi_range => '$number' and lo_range =<
    '$number')"; However, the problem I have now would be that I have no examples of a form to populate the php query to the database. I have the form and its six input fields defined, but I am having a difficult time getting my submit results into my query. Any thoughts

  4. #4
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, that whats your SQL query should look like.


    PHP automatically generates variable names for the form feilds. Example

    <INPUT TYPE="TEXT" NAME="name">

    on submitting would create a variable $name.
    All you need to do is process it. For the compulsory feilds, you need to check if they were entered like this

    if (!$name) {
    die ("Error.. field required");
    }

    This would make sure the Name field is always filled out.

    Similarly, you can use the other variables for the other tests. Hope this helps.
    i dunno...

  5. #5
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Clay County, Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You, This is the code I have so far. However, I cannot seem to get the submit into the query.

    <?php

    if ($submit) {

    // process form

    while (list($name, $value) = each($HTTP_POST_VARS)) {
    echo "$name = $value<br>\n";
    }
    } else{

    // Display Form

    ?>

    <form method="post" action="<?php echo $PHP_SELF?>">
    <input type="text" name="number" size="6"> Address Number<p>
    <select name="direction" size="1" tabindex="1">
    <option selected>Optional</option>
    <option value="N">N</option>
    <option value="S">S</option>
    <option value="E">E</option>
    <option value="W">W</option>
    <option value="NE">NE</option>
    <option value="SE">SE</option>
    <option value="NW">NW</option>
    <option value="SW">SW</option>
    </select> Pre Direction<p>
    <input type="text" name="name" size="25" tabindex="2"> Name<p>
    <select name="type" size="1" tabindex="3">
    <option selected>pick one</option>
    <option value="AVE">AVE</option>
    <option value="BLVD">BLVD</option>
    <option value="CIR">CIR</option>
    <option value="CT">CT</option>
    <option value="DR">DR</option>
    <option value="FWY">FWY</option>
    <option value="HWY">HWY</option>
    <option value="LOOP">LOOP</option>
    <option value="LN">LN</option>
    <option value="MNR">MNR</option>
    <option value="MT">MT</option>
    <option value="PKWY">PKWY</option>
    <option value="PL">PL</option>
    <option value="RD">RD</option>
    <option value="ST">ST</option>
    <option value="TRL">TRL</option>
    <option value="TER">TER</option>
    <option value="TRCE">TRCE</option>
    <option value="WAY">WAY</option>
    </select> Type<p>
    <select name="post_dir" size="1" tabindex="1">
    <option selected>Optional</option>
    <option value="N">N</option>
    <option value="S">S</option>
    <option value="E">E</option>
    <option value="W">W</option>
    <option value="NE">NE</option>
    <option value="SE">SE</option>
    <option value="NW">NW</option>
    <option value="SW">SW</option>
    </select> Post Direction<p>
    <input type="text" name="zipcode" size="5" tabindex="4"> Zip Code<br>

    <input type="submit" name="submit" value="Find Precinct!!">
    </form>

    <?php

    } // end if

    ?>


    <?

    $db= MYSQL_CONNECT(localhost, *****, ******);
    mysql_select_db(*********,$db);
    ?>
    <?
    if ($submit) {
    $sql = "SELECT * FROM vrstrt WHERE (hi_range => '$number' and lo_range =<
    '$number')";
    $result = mysql_query($sql);

    while ($myrow = mysql_fetch_array($result)) {

    printf ("Precinct: %s\n<br>", $myrow["precinct"]);}}
    ?>

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To my knowledge, =< and => are not valid operators in mySQL.
    You need to use >= and <= in your query.
    http://www.mysql.com/doc/C/o/Comparison_functions.html

  7. #7
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Clay County, Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are correct!

    Thank you, I found the error in the mysql book that just happened to arrive that day. As I said earlier in the post, I am new to php and MySql and look forward to learning more. Once again thank you for the help....

  8. #8
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Clay County, Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql = "SELECT * FROM vrstrt WHERE name = '$address' AND(hi_range >= '$number' and lo_range <= '$number')AND zipcode = '$zip'";
    $result = mysql_query($sql);
    while ($myrow = mysql_fetch_array($result)) {

    printf ("Precinct: %s\n <br>", $myrow ["precinct"]);}}

    In addition to making sure that $number is within the range, I have an additional requirement is to determining if $number is odd or even.

    Once that is known could I compare the result to a odd or even column that would then result $myrow

    To describe this requirement, I have some precincts that fall within the same number range, however, a odd or even street number determines if its in precinct a or b.

  9. #9
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To determine if $number is even:
    Code:
    if ( ($number % 2) == 0 ) {
       // $number is even
    } else {
       // number is odd!
    }


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
  •