#1
  1. No Profile Picture
    chaz goodsell
    Guest
    Devshed Newbie (0 - 499 posts)
    I'm a newbie to all the above.
    What I'm looking for is an example on using a form to query the database and displaying the information to the current page.I have a small database "workdb" comprised of 1 table "employees" 6 fields "id, first, last, address, position,phone number". I'm attempting to allow a regular user to type a field value into the form and have all the information associated with that value display. ie; typing in last"a last name".
    Thanks for any help.
    chaz
  2. #2
  3. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Well, it's not quite that simple. What do you do if you have more than one employee with the same last name? (or any other field that might not be unique)

    Do you want to display information only? Then it's no problem, you'd display all individuals with the same last name.

    If you wanted to allow editing you could display all individuals with matching criteria with a radio button and let the user select which person he wanted before going to the edit form. You could also just display each individual in their own form on the same page but that could get confusing, make mistakes more likely, and also introduce more difficulties to keep track of all the data.

    Post more info on what you envision happening and what you want it to do.

    Rod
  4. #3
  5. No Profile Picture
    chaz goodsell
    Guest
    Devshed Newbie (0 - 499 posts)
    Rod,

    I'm just looking to display the information. Ihave already created a form for editing and adding a record " locked down by rights". the goal here is to simply display the info "all" associated with the last name even if duplicates exist. thanks for the help.
  6. #4
  7. No Profile Picture
    chaz goodsell
    Guest
    Devshed Newbie (0 - 499 posts)
    This what I have managed to learn thus far, but still not working.
    <?php
    $db =mysql_connect ("localhost","user name","valid password");
    mysql_select_db("workdb",$db);
    if($last) {
    // query DB
    $sql = "SELECT * FROM employees WHERE last ='$last'";
    $result = mysql_query($sql);

    //display data
    }else{
    //display form
    ?>
    <form method=post action="<?php echo $PHP_SELF?>">
    <input type="text" name="last"> <input type="submit">
    </form>
    <?php
    }
    echo $sql
    ?>
    With the echo $sql " I verify correct sql statement. With it commented out I get the following:
    Document contains no data.
    Anyone out there see what I'm missing?
    I've tried placing the name in all caps, lower and as it show's up with in the database.
  8. #5
  9. No Profile Picture
    wesb
    Guest
    Devshed Newbie (0 - 499 posts)
    Try adding this piece of code just below the line "$result = mysql_query($sql);"

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>if(mysql_num_rows($result) > 0){
    while($row=mysql_fetch_array($result)){
    echo "First Name: $row[first]<br>";
    echo "Last Name: $row[last]<br><br>";
    }
    }else{
    echo "No results found.";
    }[/quote]

    The document contains no data error means exactly what it says, your script is returning a document to the browser that contains nothing.

    ------------------
    wesb@devshed.com
    www.devshed.com
  10. #6
  11. No Profile Picture
    chaz goodsell
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks wesb.
    That has done the trick!!!!!
    Outstanding....

Similar Threads

  1. Invalid characters with PHP and MySQL
    By gio50000 in forum MySQL Help
    Replies: 2
    Last Post: November 18th, 2004, 08:59 AM
  2. About forms, php, and mysql
    By ekyl in forum PHP Development
    Replies: 2
    Last Post: November 5th, 2003, 11:51 AM
  3. Replies: 8
    Last Post: August 30th, 2003, 10:04 AM
  4. Replies: 0
    Last Post: August 26th, 2003, 02:57 PM
  5. Cronjob madness
    By eliteboo in forum Linux Help
    Replies: 10
    Last Post: July 14th, 2003, 10:49 AM

IMN logo majestic logo threadwatch logo seochat tools logo