dannyone Posted March 23, 2009 Share Posted March 23, 2009 hello everyone i am creating a list of dynamic checkboxes that are been pulled from my mysql db. i can get them to display correctly, but i want to simply echo the value that the user has selected. but atm its not displaying anything. can some1 help please, heres my code <?php require_once('auth1.php'); require_once('config.php'); ?> <html> <form method="post" action="<?php echo $PHP_SELF;?>"> <?php $room = $_POST['room']; mysql_connect("localhost", "xx", "xx") or die(mysql_error()); mysql_select_db("xx") or die(mysql_error()); //$query=("select * from categories"); $result = mysql_query("SELECT * FROM Rooms") or die(mysql_error()); while($row=mysql_fetch_array($result)){ echo "<input type='checkbox' value='' name='room' />$row[Room_ID]<br/> "; } // this will display all checkboxes w/ values in db. echo $_POST['room']; ?> <input type="submit" value="Select Availability" name="submit"> </form> </html> on submit i would like the rooms they have selected just to be echo'd on the screen thanks again Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 23, 2009 Share Posted March 23, 2009 I dont see any code updating the database for the rooms the user selected. Also, every one of your checkboxes has the same "name" identifier which i dont think is a proper way of doing it. each input should have a unique identifier Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 23, 2009 Share Posted March 23, 2009 If you change your checkboxes to this echo "<input type='checkbox' value='' name='room[]' />$row[Room_ID]<br/> "; then it will be an array so you can do this foreach($_POST['room'] as $room) { echo $name; } hello everyone i am creating a list of dynamic checkboxes that are been pulled from my mysql db. i can get them to display correctly, but i want to simply echo the value that the user has selected. but atm its not displaying anything. can some1 help please, heres my code <?php require_once('auth1.php'); require_once('config.php'); ?> <html> <form method="post" action="<?php echo $PHP_SELF;?>"> <?php $room = $_POST['room']; mysql_connect("localhost", "xx", "xx") or die(mysql_error()); mysql_select_db("xx") or die(mysql_error()); //$query=("select * from categories"); $result = mysql_query("SELECT * FROM Rooms") or die(mysql_error()); while($row=mysql_fetch_array($result)){ echo "<input type='checkbox' value='' name='room' />$row[Room_ID]<br/> "; } // this will display all checkboxes w/ values in db. echo $_POST['room']; ?> <input type="submit" value="Select Availability" name="submit"> </form> </html> on submit i would like the rooms they have selected just to be echo'd on the screen thanks again Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 echo '<input type="checkbox" value="'.$row['Room_ID'].'" name="room'.$row['Room_ID'].'" />'.$row[Room_ID].'<br/> '; This will build all your checkboxes with unique names. Then to check something like this: if ($_POST['room'.$row['Room_ID']]) { //checkbox was selected } Quote Link to comment Share on other sites More sharing options...
dannyone Posted March 23, 2009 Author Share Posted March 23, 2009 thanks everyone for the replys i have tried using your answer taquitosensel but it still doesn't echo anything. and i have also tried yesideez solution but that just gives me a blank screen? is there anything else i could try? thanks again for the help guys its must appreciated! thanks Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 What script is checking the checkboxes? Quote Link to comment Share on other sites More sharing options...
syed Posted March 23, 2009 Share Posted March 23, 2009 use print_r($_POST), see what $_POST contains Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 23, 2009 Share Posted March 23, 2009 try print_r($_POST) at the top of your page to make sure it's being posted. if it's not then make sure that your form is set to post and not get <form action='whatever.php' method='post'> double check to make sure your form opening and closing tags are in the right place Quote Link to comment Share on other sites More sharing options...
dannyone Posted March 23, 2009 Author Share Posted March 23, 2009 thanks everyone for the replys, i have tried using print_r($_POST) and it gives me this; Array ( [room] => [submit] => Select Availability ) what does this mean? im guessing its not storing the value? thanks Quote Link to comment Share on other sites More sharing options...
dannyone Posted March 23, 2009 Author Share Posted March 23, 2009 iv been working on this for a bit now since the last comment and iv got a little further. when i echo the value now it always shows the last value that is been called from the mysql table. can some1 help and just see were im going wrong please, im really stuck <form method="post" action="<?php echo $PHP_SELF;?>"> <body> <?php mysql_connect("localhost", "xx", "xx") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("xx") or die(mysql_error()); "<br/>"; echo "Connected to Database"; "<br>"; "<br>"; $query=("select Room_ID, RoomName from Rooms ORDER BY Room_ID"); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); while($row=mysql_fetch_array($result)){ $category = $row["Room_ID"]; "<br/>"; "<br/>"; echo "<input type=\"checkbox\" name=\"category[]\" value=\"\"> $category:"; echo "<br>"; } echo "".$category.""; ?> <input type="submit" value="submit" name="submit"> <br /> <br /> </form> </html> thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.