Ive created a form where i want someone to put in their name and email address how do i get this to be input into the mysql db using php?

heres the code:

<?php
// Connecting, selecting database
$link = mysql_connect('127.0.0.1', 'root', '')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('db') or die('Could not select database');

// Performing SQL query
$query = 'select*from table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

<form action="link.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="email" />
<input type="submit" />
</form>

then this 'link.php' from the form is below:

<html>
<body>
<?php
$name = strip_tags(trim($POST["name"]));
$email = strip_tags(trim($
POST["email"]));
$label_array = array ("name" => "name","email" => "email");
foreach ($_POST as $field => $value)
echo"{$label_array[field]}";
// Connecting, selecting database
$link = mysql_connect('127.0.0.1', 'root', '')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('db') or die('Could not select database');
// Performing SQL query
$query = 'select*from table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>

</body>
</html>

If you can help i will be very greatful as its part of my archaeology + GIS masters

Many thanks

Gary

    When posting PHP code, please use the board's [PHP][/PHP] bbcode tags - they make the code much, much easier to read (as well as aiding the diagnosis of syntax errors). You should edit your post now and add these bbcode tags to help others in reading/analyzing your code.

      As far as I can see there's no insert statement in you link.php code

      INSERT INTO `users` (
      `name` ,
      `email`
      )
      VALUES (
      '$name', '$email'
      );
        Write a Reply...