laurajohn89 Posted March 30, 2010 Share Posted March 30, 2010 Hi. I have created an 'edit event' page for my horse riding website. However, I cannot get the checkboxes to appear like they have been previously checked. Please can you help. I am running out of options. I currently have: $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'db63932_hello'; mysql_select_db($dbname); $id = $_GET["id"]; $sql = "SELECT * FROM events WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="editevent.php" method="post"> <input type=hidden name="id" value=""> <table width="100%"> <tr> <td width="50%">Title: </td> <td width="50%"> <input type="text" VALUE="<?php echo $myrow["title"] ?>"name="title" /> </td> </tr> <tr> <td width="100%">Type of Event: </td> </tr> <tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[combinedtraining]" value="Combined Training" <?php echo $myrow["type"]?"checked":""; ?>/>Combined Training</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[dressage]" value="Dressage" <?php echo $myrow["type"]?"checked":""; ?>/>Dressage</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[demostrials]" value="Demos / Trials" <?php echo $myrow["type"]?"checked":""; ?> />Demos / Trials</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[driving]" value="Driving" <?php echo $myrow["type"]?"checked":""; ?>/>Driving</p></td> </tr> <tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[endurance]" value="Endurance" <?php echo $myrow["type"]?"checked":""; ?>/>Endurance</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[eventing]" value="Eventing" <?php echo $myrow["type"]?"checked":""; ?>/>Eventing</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[exracehorseclasses]" value="Ex-Racehorse Classes" <?php echo $myrow["type"]?"checked":""; ?>/>Ex-Racehorse Classes</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[funsponsored]" value="Fun / Sponsored" <?php echo $myrow["type"]?"checked":""; ?>/>Fun / Sponsored</p></td> </tr> <tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[hunting]" value="Hunting" <?php echo $myrow["type"]?"checked":""; ?>/>Hunting</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[jumpcross]" value="Jumpcross" <?php echo $myrow["type"]?"checked":""; ?>/>Jumpcross</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[ride]" value="Ride" <?php echo $myrow["type"]?"checked":""; ?>/>Ride</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[saleauction]" value="Sale/Auction" <?php echo $myrow["type"]?"checked":""; ?>/>Sale / Auction</p></td> </tr> <tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[showjumping]" value="Show Jumping" <?php echo $myrow["type"]?"checked":""; ?>/>Show Jumping</p></td> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="type[showsmixeddiscplins]" value="Shows/Mixed Discplins" <?php echo $myrow["type"]?"checked":""; ?>/>Shows / Mixed Discplins</p></td> [/code] This just checks them all though... Link to comment https://forums.phpfreaks.com/topic/197000-edit-with-checkboxes-php/ Share on other sites More sharing options...
gwolgamott Posted March 30, 2010 Share Posted March 30, 2010 What exactly is the problem? You want only some of them to be checked? having checked at all inside of the input bracket will make it pre-checked. Link to comment https://forums.phpfreaks.com/topic/197000-edit-with-checkboxes-php/#findComment-1034272 Share on other sites More sharing options...
laurajohn89 Posted March 30, 2010 Author Share Posted March 30, 2010 I want the ones that have previously been checked to be checked. Sorry this sounds confusing. Say showjumping was the only one checked and then the user wanted to edit this event. When they click on edit, only showjumping should be ticked. Many thanks Link to comment https://forums.phpfreaks.com/topic/197000-edit-with-checkboxes-php/#findComment-1034312 Share on other sites More sharing options...
gwolgamott Posted March 30, 2010 Share Posted March 30, 2010 Ok I understand. Whats the source code look like when that runs? I'd like to see what <?php echo $myrow["type"]?"checked":""; ?> is actually printing out for non-checked flags. That may be the issue right there. To make sure it is returning "" and nothing else EDIT: Also just try the longhand version here too <?php if($myrow["type"] != "") echo "checked"; ?> Link to comment https://forums.phpfreaks.com/topic/197000-edit-with-checkboxes-php/#findComment-1034317 Share on other sites More sharing options...
laurajohn89 Posted March 31, 2010 Author Share Posted March 31, 2010 it just checks them all. If I type <?php echo $myrow["type"]?"checked":""; ?> at the bottom again it just says checked. Link to comment https://forums.phpfreaks.com/topic/197000-edit-with-checkboxes-php/#findComment-1034665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.