• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

checkboxen abfragen

htmler123

Neues Mitglied
wie stelle ich die if-Abfrage damit sie herausfindet ob das Häckchen der Checkbox gesetzt wurde oder nicht?
 
Wo speicherst du den Wert der Checkbox denn? In einer Datenbank? In einer Variable? Textdokument? Cookie?

MfG Icy
 
Hier mal der code


<td></td><td></td><td><inputtype="checkbox"name="speichern" /><b>passwort speichern ??</b></td>
</tr>
</table>

PHP:
<?php
if ($_POST['name']==  (Und hier ist das große ?)
setcookie("savepw","yes",time()+86400*30);
?>
 
In dem Falle musst du nur das gesetzte Cookie abfragen.

PHP:
<?php
if (isset($_COOKIE['savepw']) and $_COOKIE['savepw'] == "yes")) {
  echo "Häkchen ist gesetzt!";
} else {
  echo "Häkchen ist nicht gesetzt!";
}
?>

MfG Icy
 
Kann mir jemand den fehler in diesem script zeigen? ich komme einfach nicht drauf :(

Code:
[SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]
<form[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]action[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"index.php"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]method[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"post">[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]<table[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]align[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"center"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]<tr>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]<td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]<b>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]Passwort:[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]</b>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]</td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]<td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]<input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]type[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"password"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"jonas"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] /[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]</td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]<td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]<input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]type[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"submit"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]value[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"senden"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] /[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]</td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]</tr>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]<tr>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]<td></td><td></td><td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]<input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]type[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"checkbox"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]"speichern"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] /[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]><b>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]passwort speichern ??[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]</b>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]</td>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]</tr>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]</table>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0]</form>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
<?php
if (isset($_POST['speichern'])){
setcookie("savepw","yes",time()+86400*30);
}
?>

<?php if (isset($_COOKIE["savepw"]) && $_COOKIE["savepw"]=="yes"){
echo "jo";
}
?>
[/SIZE]
 
Ist das ein Bug in der Code-Funktion oder hast du wirklich alles zusammen geschrieben? Bei mir steht zum Beispiel:

HTML:
<formaction="index.php"method="post">

Das hast du aber nicht in deinem Script alles so ohne Leerzeichen stehen, oder?

MfG Icy
 
Wenn das setzen des Cookies und das Abfragen des Cookies innerhalb desselben Scriptes ist, wird es nicht funktionieren. Das Cookie ist erst nach Beendigung des Scriptes verfügbar.

Gruß thuemmy
 
Desweiteren wolltest du doch nur wissen wie man auf eine "angekreuzte" Checkbox prüft. Und genau das tust du doch mit isset($_POST["feldname"]). Deine Frage sollte daher eigentlich beantwortet worden sein!
 
Welches Problem?

Dies hier:
PHP:
if (isset($_POST['speichern'])){
setcookie("savepw","yes",time()+86400*30);
}
?>

<?php if (isset($_COOKIE["savepw"]) && $_COOKIE["savepw"]=="yes"){
echo "jo";
}
ist Unsinn.

PHP:
if (isset($_POST['speichern'])){
  setcookie("savepw","yes",time()+86400*30);

  echo "jo";
}

Tut das Gleiche!
 
Welches Problem?

Dies hier:
PHP:
if (isset($_POST['speichern'])){
setcookie("savepw","yes",time()+86400*30);
}
?>
 
<?php if (isset($_COOKIE["savepw"]) && $_COOKIE["savepw"]=="yes"){
echo "jo";
}
ist Unsinn.

mit der funktion wollte ich herausfinden ob die cookie gesetzt ist

PHP:
if (isset($_POST['speichern'])){
  setcookie("savepw","yes",time()+86400*30);
 
  echo "jo";
}

Tut das Gleiche!

und hier wird einfach jo ausgegeben wenn die checkbox angekreutzt wurde

ich will aber das jo ausgegeben wird wenn die cookie bereits existiert
 
PHP:
if (isset($_POST['speichern'])){
  setcookie("savepw","yes",time()+86400*30);
}

if ((isset($_COOKIE["savepw"]) && $_COOKIE["savepw"]=="yes") || isset($_POST['speichern'])){
  echo "jo";
}
 
Verstehst du überhaupt die Logik des Codes?

Was willst du eigentlich machen?

Das Cookie nur setzen wenn die Checkbox angekreuzt wurde und noch kein Cookie gesetzt ist?

Wenn ja, dann brauchst du doch nur noch diesen Satz als PHP-Bedingung formulieren! Wo ist das Problem?
 
Zurück
Oben