php - How do I display the user input in checkboxes? -
this php code checkboxes:
<b>interests:</b> <input type="checkbox" name="interests" value="interests">nature/wildlife <input type="checkbox" name="interests" value="interests">arts/museum <input type="checkbox" name="interests" value="interests">neighbourhoods
how display user input in next page? showing user has ticked.
making appear
interests:
nature/wildlife
arts/museum
using $_post method
showing full code:
<head> <link rel="stylesheet" href="styles.css"> <style> #nav { text-align:left; } </style> </head> <body> <div id="header"> <h1> <img src="images/footprints.jpg"> singapore footprints</h1> </div> <div id="nav"> <form action="visitorprofile.php" method="post"> <p> <!-- write codes add textbox name --> <b>name:</b> <input type="text" name="name" size="20" maxlength="40"value=""/> </p> <p> <!-- write codes add textbox userid --> <b>userid:</b> <input type="text" name="userid" size="20"/> </p> <p> <!-- write codes add textbox password --> <b>password:</b> <input type="password" name="pwd" size="20"/> </p> <p> <!-- write codes add textbox contact number --> <b>contact number:</b> <input type="text" name="contactno" size="20"/> </p> <p> <!-- write codes add radio buttons status, either local or tourist --> <b>status:</b> <input type="radio" name="status" value="local">local <input type="radio" name="status" value="tourist">tourist</br> </p> <p> <!-- write codes add checkboxes interests --> <b>interests:</b> <input type="checkbox" name="interests[]" value="nature/wildlife">nature/wildlife <input type="checkbox" name="interests[]" value="arts/museum">arts/museum <input type="checkbox" name="interests[]" value="neighbourhoods">neighbourhoods </p> <input type="submit" name="submit" value="register me!" /> <input type="reset" value="reset" /> </form> </div> <div id="footer"> copyright © school of iit </div> </body> </html>
which links this:
<!doctype html> <html> <head> <link rel="stylesheet" href="styles.css"> <style> #nav { text-align:centre; } </style> </head> <body> <?php $name=$_post['name']; $userid=$_post['userid']; $contactno=@$_post['contactno']; $status=$_post['status']; ?> <div id="header"> <h1> <img src="images/footprints.jpg"> singapore footprints</h1> </div> <div id="nav"> thank registering us. <?php echo "thank you, <b>$name</b>.<br/>"; echo '</p>'; echo "<b>you have entered following details:</b><br/>"; echo "<b>userid:</b> $userid <br/>"; echo "<b>contact number:</b> $contactno <br/>"; echo "<b>status:</b> $status <br/>"; $topics = $_post['interests']; if(empty($topics)) { echo("you didn't select anything"); } else { $n = count($topics); echo("you selected $n topic(s): "); for($i=0; $i < $n; $i++) { echo($topics[$i] . " "); } } ?> <br> <br> please <a href="comments.html">click here</a> continue. </div> <div id="footer"> copyright © school of iit </div> </body> </html>
if write input name square brackets, can access selected value in array:
<input type="checkbox" name="interests[]" value="nature/wildlife">nature/wildlife <input type="checkbox" name="interests[]" value="arts/museum">arts/museum <input type="checkbox" name="interests[]" value="neighbourhoods">neighbourhoods
if submit form post, on loaded page $_post['interests']
contains selected values
Comments
Post a Comment