Dysan wrote:Oops! Sorry, I didn't explain my question correctly.
How do I adding records to the database using the following code, upon a link being clicked?:
mysql_select_db("my_db", $con);
$sql="INSERT INTO person (firstName, lastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
If you want to insert the information into the database you would do this.
First you would build a form
(insert.html)
<html>
<head>
<title>Uploading to a database</title>
</head>
<body>
<form method="POST">
<table border="1">
<tr>
<td width="100">First Name:</td> <td><input type="text" name="firstname"></td>
</tr>
<tr>
<td width="100">Last Name:</td> <td><input type="text" name="lastname"></td>
</tr>
<tr>
<td width="100">Age:</td> <td><input type="text" name="age"></td>
</tr>
<tr>
<td> </td> <td><input type="submit" name="save" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
Now we are ready to add the data to the database.
(insert2.php)
<?php
$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("YOUR DATABASE", $con);
$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "$_POST['firstname] has been added";
mysql_close($con)
?>
The php coding was taken from W3 Schools
http://youtube.com/watch?v=Y1Serk8yp28
I added a video explaining it all.
If you still need help just post.