PDA

Click to See Complete Forum and Search --> : Entry Form Database...


wookie224
Jul 17th, 2003, 12:37 PM
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

The Hobo
Jul 17th, 2003, 03:36 PM
If you're talking MySQL database, it would go like this:

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.

wookie224
Jul 17th, 2003, 04:14 PM
Thanks! Worked great!

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

Thank you for the help

The Hobo
Jul 17th, 2003, 04:50 PM
Following the previous example I gave:

$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!";
}