Doctrcid Posted January 26, 2010 Share Posted January 26, 2010 Hey, i am using php as my language for a computing a2 project and needs some help.i have a database and everything done, what i need to know is...is there any code that if a button is pressed in a form it submits the data in the form then sends you back to the form again so you can add more of the same data.if you dont understand i will post my code later heres the code for the button<input type="button" value="Add Another Computer"> <input type="submit" />sorry if i dont make much sense i am quite a novice and literally learning this as i go...help would be appreciated asapthank you Link to comment Share on other sites More sharing options...
justsomeguy Posted January 26, 2010 Share Posted January 26, 2010 The best way is to have the form submit to itself, and have PHP code on that page which checks if the form was submitted and processes the information, then displays the form again. Since everything is on the same page you can also fill out the values they typed in if there was an error. Check the PHP forms tutorial on the w3schools site, and there's more information here:http://w3schools.invisionzone.com/index.ph...ost&p=96606It would look basically like this: <?php$fname = '';$lname = '';$errors = '';if (isset($_POST['submit'])){ $fname = $_POST['fname']; $lname = $_POST['lname']; if ($fname == '') { $errors .= 'You must enter your first name.'; } if ($lname == '') { $errors .= 'You must enter your last name.'; } if ($errors == '') { // do something with the form data $fname = ''; $lname = ''; }}?><html>...<form method="post"><?php echo $errors; ?><input type="text" name="fname" value="<?php echo $fname; ?>"><input type="text" name="lname" value="<?php echo $lname; ?>"><input type="submit" name="submit" value="Submit"></form></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.