View Full Version : simple roster form
koolkrasher
December 11th, 2007, 07:33 PM
any one have a good tutorial for a simple roster input form? Some thing that can input more than 1 player at a time to a database? Ive done soem searchers but nothing good enough.
simplistik
December 11th, 2007, 08:24 PM
ummm... just make a form w/ multiple fields...
koolkrasher
December 11th, 2007, 10:00 PM
ive done that but i need multiple fields with the same name. ive tried diff things and nothing worked =/
for example i would like a form with 10 fields for player names and each name will be added to the player name col in the db
simplistik
December 11th, 2007, 11:14 PM
<?php
if ( isset( $_POST['post'] ) )
{
$names = $_POST['name'];
$i = 1;
foreach ( $names as $name )
{
$name = trim($name);
$value[$i] = $name;
if ( !empty($name) )
{
printf( 'INSERT INTO player (player_id, name) VALUES ("","'.$name.'")' );
}
++$i;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-language" content="en-US" />
<title></title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" >
<ol>
<?php
for ( $i = 1; $i <= 10; ++$i )
{
?>
<li>
<label><span>Name</span>
<input type="text" name="name[]" value="<?php echo $value[$i]; ?>" />
</label>
</li>
<?php
}
?>
</ol>
<input type="submit" name="post" value="Submit" />
</form>
</body>
</html>
you should be able to figure the rest out... any more help and I'll have to start chargin ;) :P. and also if you know how to do extended inserts i'd recommend that's how you insert your data. i didn't do it here cause i figured you may not have understood it if I did.
koolkrasher
December 12th, 2007, 01:18 AM
Thanks for all the help simplistik. sorry for beeing such a newb, you helped alot.
Thanks again.
simplistik
December 12th, 2007, 08:45 AM
Not much of a problem man, when you ask big question like you did it's difficult to decide whether to give you the whole chunk of code cause it's essentially free work :lol:, but tis the season ;).
Also, don't forget to secure your data to your database too by escaping illegal characters and what not http://us3.php.net/function.mysql-real-escape-string
koolkrasher
December 14th, 2007, 03:53 PM
thanks for the tip i apreciate it
joran420
December 14th, 2007, 05:33 PM
oh sweet I didnt know you could do a POST array :P
Ive been doing something similar but making unique field names...woot that will cut down on some work
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.