Results 1 to 4 of 4

Thread: Entry Form Database...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Location
    Allen, Texas
    Posts
    125

    Entry Form Database...

    Does anyone have a sample page where a user can enter information into a form and insert it into a database?

    One to view the info would be nice too.

    Thanks

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    If you're talking MySQL database, it would go like this:

    Code:
    if (isset($_POST['submit'])) {
        $sql = "INSERT INTO tblName (name, email) VALUES ";
        $sql .= "('" . $_POST['name'] . "', '" . $_POST['email'] . "')";
    
        $result = mysql_query($sql) or die(mysql_error());
        if ($result) {
            echo "Data entered successfully!";
        } else {
            echo "Failed to insert data!";
        }
    } else {
        echo '<form action="insert.php" method="post">
            <b>Name</b>: <input type="text" name="name">
            <b>Email</b>: <input type="text" name="email">
    
            <input type="submit" name="submit" value=" Add ">
        </form>';
    }
    But, of course, you must have a database, table, and fields setup before it'll work.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Location
    Allen, Texas
    Posts
    125

    what if

    Thanks! Worked great!

    Now... What is the easiest way to display some records?

    Thank you for the help
    Last edited by wookie224; Jul 17th, 2003 at 04:41 PM.

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Following the previous example I gave:

    Code:
    $people = mysql_query("SELECT * FROM tblName") or die(mysql_error());
    
    if ($person = mysql_fetch_array($people)) {
        do {
            echo '<a href="mailto:' . $person['email'] . '">' . $person['name'] . '</a><br>";
        } while ($person = mysql_fetch_array($people));
    } else {
        echo "No people found!";
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width