Jump to content

edit with checkboxes php


laurajohn89

Recommended Posts

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

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

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";  ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.