Encontré este código en Internet y quiero tener estas entradas: casilla de verificación de nombre con 5 elementos
este código guarda la información del usuario que seleccionó en la casilla de verificación y su nombre en un archivo de texto
alguien me puede ayudar a arreglar esto?
<!DOCTYPE html> <?php if(isset($_POST['submit'])){ $Name = "Username:".$_POST['username']." "; $Pass = "Password:".$_POST['password']." "; $file=fopen("saved.txt", "a"); fwrite($file, $Name); fwrite($file, $Pass,); echo fwrite($file,"*************************",); fclose($file); } ?> <html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('.check').click(function() { $('.check').not(this).prop('checked', false); }); }); </script> <BODY> <form action = "post.php" method="POST"> <p> <label>Login Name:</label><input type = "text" name = "name" /><br> <input type="checkbox" type = "password" name="pwd[]" class="check" value="male"> Male <input type="checkbox" type = "password" name="pwd[]" class="check" value="female"> Female <input type="checkbox" type = "password" name="pwd[]" class="check" value="other"> Other <br/> <br/> </p> <input type = "submit" name="submit_btn" id = "submit" value = "submit"/> <input type = "reset" id = "reset" value = "reset"/> </form> </BODY> </html>Su matriz de publicación contiene un elemento con el nombre de sus campos de entrada. esto funcionará
<!DOCTYPE html> <?php if(isset($_POST['submit'])){ $Name = "Username:".$_POST['name']." "; $Pass = "Password:".$_POST['pwd']." "; $file=fopen("saved.txt", "a"); fwrite($file, $Name); fwrite($file, $Pass,); echo fwrite($file,"*************************",); fclose($file); } ?> <html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('.check').click(function() { $('.check').not(this).prop('checked', false); }); }); </script> <BODY> <form action = "post.php" method="POST"> <p> <label>Login Name:</label><input type = "text" name = "name" /><br> <input type="checkbox" type = "password" name="pwd" class="check" value="male"> Male <input type="checkbox" type = "password" name="pwd" class="check" value="female"> Female <input type="checkbox" type = "password" name="pwd" class="check" value="other"> Other <br/> <br/> </p> <input type = "submit" name="submit" id = "submit" value = "submit"/> <input type = "reset" id = "reset" value = "reset"/> </form> </BODY> </html>Primero tendrá que entender cómo funciona el formulario.
Solicita los datos posteriores de $_POST["username"] y $_POST["password"] . Esos "Nombres" están definidos por el Atributo "nombre" de la Entrada correspondiente. Entonces, para obtener un nombre de usuario, deberá tener una Entrada como <input type="text" name="username" /> .
Mire ahora su propio HTML: ha definido una entrada para el nombre de los usuarios, pero tiene el atributo name="name" . Esto dará como resultado que los datos posteriores se almacenen en $_POST["name"] .
Además, solo tiene una entrada, pero solicita dos valores (nombre de usuario Y contraseña).
En cuanto a sus casillas de verificación, no entiendo la razón por la que sus nombres son name="pwd[]" , pero probablemente también debería cambiarlas. También especifica dos tipos, pero ese segundo type="password" no se reconoce.
Editar: revisé nuevamente y decidí volver a trabajar completamente tu código:
<!DOCTYPE html> <?php if(isset($_POST['submit'])){ $Name = "Username:".$_POST['username']; $gender = "Gender:".$_POST['gender']; $file=fopen("saved.txt", "a"); fwrite($file, $Name); fwrite($file, $Pass); fwrite($file,"*************************"); fclose($file); } ?> <html> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('.check').click(function() { $('.check').not(this).prop('checked', false); }); }); </script> <form action = "post.php" method="POST"> <p> <label>Login Name:</label><input type = "text" name = "username" /> <br> <input type="checkbox" name="gender" class="check" value="male"> Male <input type="checkbox" name="gender" class="check" value="female"> Female <input type="checkbox" name="gender" class="check" value="other"> Other <br/> <br/> </p> <input type = "submit" name="submit_btn" id = "submit" value = "submit"/> <input type = "reset" id = "reset" value = "reset"/> </form> </body> </html>Te recomiendo que aprendas más sobre formularios HTML .