Genesis730 Posted January 6, 2010 Share Posted January 6, 2010 So I'm wanting to make a page that a textbox that submits to a database then pastes the last 10 submissions onto the page... Here's an outline of what i have... how it looks isn't important, the code is. I have this form that collects the date, first name, last name, and testimonial and stores it in a database with an incrementing ID row... What I'm not sure how to do is pull the last 10 posts and echo them onto the site. Any help is appreciated... --- <?php // Connect to fake database mysql_connect("localhost","username","password") or die(mysql_error()); mysql_select_db("testimonials") or die(mysql_error()); ?> <html> <body> <h1>TESTIMONIALS</h1> <hr width="80%"><br /><br /> <?PHP // Connection Error if (!$conn) { echo "Sorry, but there seems to be a problem with the database.<br />Please try again later"; exit; } if (!mysql_select_db("mydbname")) { echo "Sorry, but there seems to be a problem with the database.<br />Please try again later"; exit; } ?> <form method="POST" action="testimonials.php"> <?PHP $date = date(' F jS Y'); ?> <table cellspacing="0" cellpadding="0" border="0" align="center" width="50%"> <tr> <td align="center">First Name<br /> <input name="firstname" value="<?PHP echo $_POST['firstname']; ?>" /> </td> <td align="center">Last Name<br /> <input name="lastname" value="<?PHP echo $_POST['lastname']; ?>" /> </td> </tr> </table> <textarea name="testimonials" rows="5" cols="40%"><?PHP echo $_POST['testimonials']; ?></textarea> <p align="center"><input type="submit" name="submit" value="Submit My Testimonial" /></p> </form> <?PHP if($_POST['submit']) { //COLLECT DATA $date = $_POST['date']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $testimonial = $_POST['testimonial']; //VALIDATION $error = ''; if (!$firstname) $error = $error."<b>First Name</b><br />"; if (!$lastname) $error = $error."<b>Last Name</b><br />"; if (!$emailaddress) $error = $error."<b>Testimonial</b><br />"; if ($error!="") echo "<span id='red'><font size='2'>Please fill out the following required fields:</font><br />$error</span>"; else { //SUBMIT DATA mysql_query("INSERT INTO testimonials VALUES(`id`,'". $date ."','". $firstname ."','". $lastname ."','". $testimonial ."')") or die(mysql_error()); } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/187498-last-10-testimonials-submit-onto-page/ Share on other sites More sharing options...
premiso Posted January 6, 2010 Share Posted January 6, 2010 For future reference, please use the to surround code in To display the testimonials: $res = mysql_query("SELECT id, `date`, firstname, lastname, testimonial FROM testimonials ORDER BY date DESC LIMIT 10"); while ($row = mysql_fetch_assoc($res)) { echo "<b>{$row['firstname']} {$row['lastname']}</b><br />on {$row['date']}<br />{$row['testimonial']}<br /><br />"; } Would be an example how to display them. Quote Link to comment https://forums.phpfreaks.com/topic/187498-last-10-testimonials-submit-onto-page/#findComment-990008 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.