Dusaro Posted August 30, 2011 Share Posted August 30, 2011 Ok, i have gots the code for posting one member at a time, I was wondering if it would be possible to make it so that you can just click a button or link and make that show another textbox that can be used to insert another member? My code is: <?php if ($_POST['post']) { $name = $_POST['name']; if ($name) { mysql_connect("localhost","slay2day_User","slay2day") or die(mysql_error()); mysql_select_db("slay2day_database") or die(mysql_error()); $insert = mysql_query("INSERT INTO members VALUES ('','$name')") or die (mysql_error()); die ("Member has been added successfully"); } else echo "Please fill out all fields"; } ?> <form action='addmember.php' method='POST'> Name: <input type='text' name='name'> <br /> <input type = 'submit' name='post' value='Add Members'> </form> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/246004-add-multiple-to-table/ Share on other sites More sharing options...
Pikachu2000 Posted August 30, 2011 Share Posted August 30, 2011 That code should actually be written a bit differently than it is. As for dynamically adding form fields, you'd need to use javascript or add a field to tell the script how many fields to add, then submit the form and redisplay it with the specified number of fields added. // due to differences in the way some browsers handle the values of <input type="submit"> buttons, if( $_POST['post'] ) { // should be written as if( strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) { Then you should check that $_POST['name'] has a value before trying to assign its value to $name if( !empty($_POST['name']) ) { $name = $_POST['name']; } else { // the field was empty, so handle the error. } Link to comment https://forums.phpfreaks.com/topic/246004-add-multiple-to-table/#findComment-1263392 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.