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