Jump to content

MYSQL PHP form help?????


imtaqi

Recommended Posts

I have php form which what do is that post the form data to Mysql Database

and show it on a page

 

for example i have a form which have following inputs

 

First Name:

Last Name:

Age:

 

its output will be sort of like that

 

----------------------------------------

First name | Last Name | Age

----------------------------------------

abc xyz 18

 

 

When Somebody fill the same information twice the result will be like this

 

--------------------------------------------

First name | Last Name | Age | Entries

--------------------------------------------

abc xyz 18 | 2

 

 

& it is giving me the following output

 

--------------------------------------------

First name | Last Name | Age

--------------------------------------------

abc xyz 18

abc xyz 18

 

The php file 2 which form post the data is insert.php given below:

 

<?php

$con = mysql_connect("localhost","myuser","password");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}mysql_select_db("my_db", $con);$sql="INSERT INTO person (id, FirstName, LastName, Age)

VALUES

('','$_POST[firstname]','$_POST[lastname]','$_POST[age]')";if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "1 record added";mysql_close($con)

?> 

 

 

My result page code is :

 

 

<?php

// ... the previous code

$con = mysql_connect("localhost","myuser","pass");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

 

mysql_select_db("my_db", $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);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/86602-mysql-php-form-help/
Share on other sites

I want to configure so that when any person enter information twice

it will give answer like this

 

---------------------------------

name    \  last name    \ queries

---------------------------------

abc      \  xyz            \ 2

----------------------------------

 

& the form above is giving me result like this

 

-------------------------------------------

name        \  last name  \ queries

-------------------------------------------

abc          \  xyz            \  0

abc          \  xyz            \  0

 

Link to comment
https://forums.phpfreaks.com/topic/86602-mysql-php-form-help/#findComment-442805
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.