Ich habe diverse Probleme mit
<input type=checkbox>. Wenn man mehrere checkboxen mit dem selben namen hat, ist das ganze doch ein array oder?
Wie überpüfe ich den array mit isset() denn?
EInfach mit ner Schleife? Ausserdem können ja mehrere Checkboxen gewählt sein, die sollen dann in EIN Feld einer Mysql Tabelle geschrieben werden, ist das so richtig?
code:
<?php
function madd()
{
global $HTTP_POST_VARS, $PHP_SELF;
if(isset($HTTP_POST_VARS["absenden"]) && $HTTP_POST_VARS["absenden"] == "Member adden" && isset($HTTP_POST_VARS["nick"]) && strlen($HTTP_POST_VARS["nick"]) >= 1 && isset($HTTP_POST_VARS["pw"]) && strlen($HTTP_POST_VARS["pw"]) >=1 && isset($HTTP_POST_VARS["email"]) && strstr($HTTP_POST_VARS["email"], "@") == true && strstr($HTTP_POST_VARS["email"], ".") == true && isset($HTTP_POST_VARS["tasks[]"]))
{
$v1 = $HTTP_POST_VARS["nick"];
$v2 = $HTTP_POST_VARS["pw"];
$v3 = $HTTP_POST_VARS["email"];
$v4 = $HTTP_POST_VARS["tasks[]"];
print $v4;
$db = mysql_connect("localhost", "admin");
mysql_select_db("gds");
mysql_query("INSERT INTO members (nick, pw, email ) VALUES ('$v1', '$v2', '$v3')", $db);
for($i=0; $i < count($v4); $i++)
{
mysql_query("INSERT INTO members (tasks) VALUES ('$v4')", $db);
}
mysql_close($db);
print('<h4>Neuen Member "').$v1.('" geaddet!');
}
else
{
print('<form method=post action="').$PHP_SELF.('">');
print(' <table border=0 cellspacing=0 cellpadding=2 align=center>');
print(' <tr>');
print(' <td align=right>');
print(' Nick:');
print(' </td>');
print(' <td align=left>');
print(' <input type=text size=23 maxlenght=48 name="nick">');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td align=right>');
print(' Password:');
print(' </td>');
print(' <td align=left>');
print(' <input type=password size=12 maxlenght=28 name="pw">');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td align=right>');
print(' Email:');
print(' </td>');
print(' <td align=left>');
print(' <input type=text size=23 maxlenght=48 name="email">');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td align=right>');
print(' Task(s):');
print(' </td>');
print(' <td align=left>');
print(' <input type=checkbox name="tasks[]" checked value="Soldier">Soldier');
print(' <input type=checkbox name="tasks[]" value="Leader">Leader');
print(' <input type=checkbox name="tasks[]" value="Co-Leader">Co-Leader');
print(' <input type=checkbox name="tasks[]" value="Serveradmin#1">Serveradmin');
print(' <input type=checkbox name="tasks[]" value="Serveradmin#2">Serveradmin#2<br>');
print(' <input type=checkbox name="tasks[]" value="Webmaster">Webmaster');
print(' <input type=checkbox name="tasks[]" value="Tactics">Tactics');
print(' <input type=checkbox name="tasks[]" value="Trials">Trials');
print(' <input type=checkbox name="tasks[]" value="PublicRelations">Public Relations');
print(' <input type=checkbox name="tasks[]" value="Kassenwart">Kassenwart');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td colspan=2 align=center>');
print(' <br><input type=submit name="absenden" value="Member adden">');
print(' </td>');
print(' </tr>');
print('</table>');
}
}
madd();
?>
<input type=checkbox>. Wenn man mehrere checkboxen mit dem selben namen hat, ist das ganze doch ein array oder?
Wie überpüfe ich den array mit isset() denn?
EInfach mit ner Schleife? Ausserdem können ja mehrere Checkboxen gewählt sein, die sollen dann in EIN Feld einer Mysql Tabelle geschrieben werden, ist das so richtig?
code:
<?php
function madd()
{
global $HTTP_POST_VARS, $PHP_SELF;
if(isset($HTTP_POST_VARS["absenden"]) && $HTTP_POST_VARS["absenden"] == "Member adden" && isset($HTTP_POST_VARS["nick"]) && strlen($HTTP_POST_VARS["nick"]) >= 1 && isset($HTTP_POST_VARS["pw"]) && strlen($HTTP_POST_VARS["pw"]) >=1 && isset($HTTP_POST_VARS["email"]) && strstr($HTTP_POST_VARS["email"], "@") == true && strstr($HTTP_POST_VARS["email"], ".") == true && isset($HTTP_POST_VARS["tasks[]"]))
{
$v1 = $HTTP_POST_VARS["nick"];
$v2 = $HTTP_POST_VARS["pw"];
$v3 = $HTTP_POST_VARS["email"];
$v4 = $HTTP_POST_VARS["tasks[]"];
print $v4;
$db = mysql_connect("localhost", "admin");
mysql_select_db("gds");
mysql_query("INSERT INTO members (nick, pw, email ) VALUES ('$v1', '$v2', '$v3')", $db);
for($i=0; $i < count($v4); $i++)
{
mysql_query("INSERT INTO members (tasks) VALUES ('$v4')", $db);
}
mysql_close($db);
print('<h4>Neuen Member "').$v1.('" geaddet!');
}
else
{
print('<form method=post action="').$PHP_SELF.('">');
print(' <table border=0 cellspacing=0 cellpadding=2 align=center>');
print(' <tr>');
print(' <td align=right>');
print(' Nick:');
print(' </td>');
print(' <td align=left>');
print(' <input type=text size=23 maxlenght=48 name="nick">');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td align=right>');
print(' Password:');
print(' </td>');
print(' <td align=left>');
print(' <input type=password size=12 maxlenght=28 name="pw">');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td align=right>');
print(' Email:');
print(' </td>');
print(' <td align=left>');
print(' <input type=text size=23 maxlenght=48 name="email">');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td align=right>');
print(' Task(s):');
print(' </td>');
print(' <td align=left>');
print(' <input type=checkbox name="tasks[]" checked value="Soldier">Soldier');
print(' <input type=checkbox name="tasks[]" value="Leader">Leader');
print(' <input type=checkbox name="tasks[]" value="Co-Leader">Co-Leader');
print(' <input type=checkbox name="tasks[]" value="Serveradmin#1">Serveradmin');
print(' <input type=checkbox name="tasks[]" value="Serveradmin#2">Serveradmin#2<br>');
print(' <input type=checkbox name="tasks[]" value="Webmaster">Webmaster');
print(' <input type=checkbox name="tasks[]" value="Tactics">Tactics');
print(' <input type=checkbox name="tasks[]" value="Trials">Trials');
print(' <input type=checkbox name="tasks[]" value="PublicRelations">Public Relations');
print(' <input type=checkbox name="tasks[]" value="Kassenwart">Kassenwart');
print(' </td>');
print(' </tr>');
print(' <tr>');
print(' <td colspan=2 align=center>');
print(' <br><input type=submit name="absenden" value="Member adden">');
print(' </td>');
print(' </tr>');
print('</table>');
}
}
madd();
?>
Kommentar