imtaqi Posted January 18, 2008 Share Posted January 18, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86602-mysql-php-form-help/ Share on other sites More sharing options...
Ken2k7 Posted January 18, 2008 Share Posted January 18, 2008 What's your question/problem? Quote Link to comment https://forums.phpfreaks.com/topic/86602-mysql-php-form-help/#findComment-442508 Share on other sites More sharing options...
revraz Posted January 18, 2008 Share Posted January 18, 2008 Do you not want them to register twice? Check to see if they exist before you Insert. Quote Link to comment https://forums.phpfreaks.com/topic/86602-mysql-php-form-help/#findComment-442531 Share on other sites More sharing options...
rameshfaj Posted January 18, 2008 Share Posted January 18, 2008 I only need to test the connection to the database server.Now i dont need to retrieve or insert any values to the database. Just to check the connection to the database server. Quote Link to comment https://forums.phpfreaks.com/topic/86602-mysql-php-form-help/#findComment-442535 Share on other sites More sharing options...
imtaqi Posted January 18, 2008 Author Share Posted January 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86602-mysql-php-form-help/#findComment-442805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.