Jump to content

add multiple to table


Dusaro

Recommended Posts

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 :P

Link to comment
https://forums.phpfreaks.com/topic/246004-add-multiple-to-table/
Share on other sites

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.
}

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.