i am using a form which post the data to MYSQL database form example if i have three inputs
a. First Name
b. Last Name
c. Age
I want to script my code in a way when some1 enter the info twice it may appear as below:
But my form is showing the following output
xyz abc 0
[COLOR=”Red”]can some body help?
The file<insert.php> which is used to post form data to MYSQL database is:
[QUOTE]
<?php
$con = mysql_connect(“localhost”,”myuser,”mypass”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}mysql_select_db(“mydatabase”, $con);$sql=”INSERT INTO person (id, FirstName, LastName, Age)
VALUES
(”,’$_POST[firstname]’,’$
{
die(‘Error: ‘ . mysql_error());
}
echo “1 record added”;mysql_close($con)
?>
The file to show output on php page is:
[QUOTE]
<?php
// … the previous code
$con = mysql_connect(“localhost”,”myuser”,”mypass”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“mydatabase”, $con);
$result = mysql_query(“SELECT * FROM person”);
echo “<table border=’1′>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>”;while($row = mysql_fetch_array($result))
{
echo “<tr>”;
echo “<td>” . $row[‘FirstName’] . “</td>”;
echo “<td>” . $row[‘LastName’] . “</td>”;
echo “<td>” . $row[‘age’] . “</td>”;
echo “<td>” . $row[‘id’] . “</td>”;
echo “</tr>”;
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum – 1;
$prev = ” <a href=”$self?page=$page”>[Prev]</a> “;
$first = ” <a href=”$self?page=1″>[First Page]</a> “;
}
else
{
$prev = ‘ ’; // we’re on page one, don’t print previous link
$first = ‘ ’; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = ” <a href=”$self?page=$page”>[Next]</a> “;
$last = ” <a href=”$self?page=$maxPage”>[Last Page]</a> “;
}
else
{
$next = ‘ ’; // we’re on the last page, don’t print next link
$last = ‘ ’; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
// and close the database connection
echo “</table>”;mysql_close($con);
?>