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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.