php - Presenting/editing checkbox values? -
hi baffling me because checkboxes in form textboxes also. enter following database new record:
<form action="processmem.php" method="post">     <table width="800" align="center">         <tr>             <td width="99" height="2"> </td>             <td width="100" height="2"> </td>             <td width="100" height="2"> </td>             <td width="100" height="2"> </td>             <td width="100" height="2"> </td>             <td width="100" height="2"> </td>             <td width="100" height="2"> </td>             <td width="100" height="2"> </td>         </tr>         <tr>             <td colspan="3" align="right" height="30">                 name               </td>             <td colspan="2" align="left">                 <input type="text" name="textfield[childname]" />             </td>             <td colspan="3"><p> </p><p> </p></td>         </tr>         <tr>             <td colspan="3" align="right" height="30">                 age               </td>             <td colspan="2" align="left">                 <input type="text" name="textfield[age]" />             </td>             <td colspan="3"><p> </p><p> </p></td>         </tr>         <tr>             <td colspan="3" align="right" height="30">                 parent name               </td>             <td colspan="2" align="left">                 <input type="text" name="textfield[parentname]" />             </td>             <td colspan="3"><p> </p><p> </p></td>         </tr>         <tr>             <td colspan="3" align="right" height="30">                 email address               </td>             <td colspan="2" align="left">                 <input type="text" name="textfield[email]" />             </td>             <td colspan="3"><p> </p><p> </p></td>         </tr>         <tr>             <td colspan="3" align="right" height="30">                 contact number               </td>             <td colspan="2" align="left">                 <input type="text" name="textfield[contactno]" />             </td>             <td colspan="3"> </td>         </tr>         <tr>             <td colspan="8" height="30"> </td>         </tr>         <tr>             <td height="15" colspan="2"> </td>             <td colspan="3" align="right">  </strong>                 check box if member  ninja!             </td>             <td align="center">                 <input type="checkbox" name="checkbox[ninja]" value="checkbox" />             </td>             <td colspan="2"> </td>         </tr>         <tr>             <td colspan="8" height="30"> </td>         </tr>         <tr>             <td height="15" colspan="2"> </td>             <td colspan="4" align="center">                 subjects has member attended?             </td>             <td colspan="2"></td>         </tr>         <tr>             <td height="5" colspan="8"> </td>         </tr>         <tr>             <td height="15"> </td>             <td colspan="2" align="center">scratch</td>             <td colspan="2" align="center">app inventor</td>             <td colspan="2" align="center">html</td>             <td> </td>         </tr>         <tr>             <td height="15"> </td>             <td colspan="2" align="center">                 <input type="checkbox" name="checkbox[scratch]" value="checkbox" />             </td>             <td  colspan="2" align="center">                 <input type="checkbox" name="checkbox[appinventor]" value="checkbox" />             </td>             <td colspan="2" align="center">                 <input type="checkbox"  name="checkbox[html]" value="checkbox" />             </td>             <td> </td>         </tr>     </table> </form> it's execeuted script:
<?php  include("connect.php"); require_once("logincheck.php");  if(isset($_post)){  $childname=mysql_real_escape_string($_post['textfield']['childname']); $age=mysql_real_escape_string($_post['textfield']['age']); $parentname=mysql_real_escape_string($_post['textfield']['parentname']); $email=mysql_real_escape_string($_post['textfield']['email']); $contactno=mysql_real_escape_string($_post['textfield']['contactno']); $ninja=isset($_post['checkbox']['ninja'])?'yes':'no'; $scratch=isset($_post['checkbox']['scratch'])?'yes':'no'; $appinventor=isset($_post['checkbox']['appinventor'])?'yes':'no'; $html=isset($_post['checkbox']['html'])?'yes':'no';  $sql="insert tblmembers (childname, age, parentname, email, contactno, ninja, scratch,  appinventor, html) values ('$childname','$age','$parentname','$email','$contactno', '$ninja','$scratch','$appinventor','$html')";mysql_query($sql) or die (mysql_error());  } this works fine, cannot see value of checkboxes if query record later, here:
$id=$_get["id"];  $sql="select * tblmembers id=".$id;  $result=mysql_query($sql);  $rows=mysql_num_rows($result);  while($row =mysql_fetch_array($result)) {  $childname=$row["childname"]; $id=$row["id"]; $age=$row["age"]; $parentname=$row["parentname"]; $email=$row["email"]; $contactno=$row["contactno"]; $ninja=$row["checkbox"]["ninja"]; $scratch=$row["checkbox"]["scratch"]; $appinventor=$row["checkbox"]["appinventor"]; $html=$row["checkbox"]["html"];  print "<p align=\"center\"><strong><i>information $childname</i><strong></p><br>"; print "<table width=\"800\" align=\"center\">";          print "<tr>"; print "<td width=\"99\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">name  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[childname]\"  value='".$childname."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">age  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield  [age] "value='".$age."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">parent name  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[parentname]\"   value='".$parentname."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">email address  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[email]\"   value='".$email."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">contact number  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[contactno]\"  value='".$contactno."'/></td>"; print "<td colspan=\"3\"> </td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"8\" height=\"30\"> </td>"; print "</tr>"; print "<tr>"; print "<td height=\"15\" colspan=\"2\"> </td>"; print "<td colspan=\"3\" align=\"right\">  </strong>check box if  member  ninja!</td>"; print "<td align=\"center\"><input type=\"checkbox\" name=\"checkbox[ninja]\" value=$row   [\"ninja\"]/></td>"; print "<td colspan=\"2\"> </td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"8\" height=\"30\"> </td>"; print "</tr>"; print "<tr>"; print "<td height=\"15\" colspan=\"2\"> </td>"; print "<td colspan=\"4\" align=\"center\">which subjects has member attended?</td>"; print "<td colspan=\"2\"></td>"; print "</tr>"; print "<tr>"; print "<td height=\"5\" colspan=\"8\"> </td>"; print "</tr>"; print "<tr>"; print "<td height=\"15\"> </td>"; print "<td colspan=\"2\" align=\"center\">scratch</td>"; print "<td colspan=\"2\" align=\"center\">app inventor</td>"; print "<td colspan=\"2\" align=\"center\">html</td>"; print "<td> </td>"; print "</tr>"; print "<tr>"; print "<td height=\"15\"> </td>"; print "<td colspan=\"2\" align=\"center\"><input type=\"checkbox\"  name=\"checkbox[scratch]\"  value='".$scratch."' /></td>"; print "<td  colspan=\"2\" align=\"center\"><input type=\"checkbox\"  name=\"checkbox[appinventor] \" value='".$appinventor."' /></td>"; print "<td colspan=\"2\" align=\"center\"><input type=\"checkbox\"  name=\"checkbox[html]\"  value='".$html."' /></td>"; print "<td> </td>"; print "</tr>"; print "</table>"; }  ?> finally - if cannot see checkbox checked on entering database, cannot edit or update record. i'm using this:
$id=$_get["id"];  include("connect.php"); require_once("logincheck.php");  if($_get["function"]=='update')  {  $childname=mysql_real_escape_string($_post['textfield']['childname']); $age=mysql_real_escape_string($_post['textfield']['age']); $parentname=mysql_real_escape_string($_post['textfield']['parentname']); $email=mysql_real_escape_string($_post['textfield']['email']); $contactno=mysql_real_escape_string($_post['textfield']['contactno']); $ninja=isset($_post['checkbox']['ninja'])?'yes':'no'; $scratch=isset($_post['checkbox']['scratch'])?'yes':'no'; $appinventor=isset($_post['checkbox']['appinventor'])?'yes':'no'; $html=isset($_post['checkbox']['html'])?'yes':'no';  $sql2="update tblmembers set  childname='".$childname."',age='".$age."',parentname='".$parentname."', email='".$email."',contactno='".$contactno."',ninja='".$ninja."',scratch='".$scratch."', appinventor='".$appinventor."',html='".$html."' id=".$id;  mysql_query($sql2) or die (mysql_error());  print "<strong>the member details have been saved. thank you.</strong><br><br><br>"; } else {  $sql="select * tblmembers id=".$id;  $result = mysql_query ($sql) or die(mysql_error());  $rows=mysql_num_rows($result);  while($row =mysql_fetch_array($result)) {  $childname=$row["childname"]; $id=$row["id"]; $age=$row["age"]; $parentname=$row["parentname"]; $email=$row["email"]; $contactno=$row["contactno"]; $ninja=$row["ninja"]; $scratch=$row["scratch"]; $appinventor=$row["appinventor"]; $html=$row["html"];  print "<form method=post action='editmember.php?function=update'>"; print "<table width=\"800\" align=\"center\">";          print "<tr>"; print "<td width=\"99\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "<td width=\"100\" height=\"2\"> </td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">name  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[childname]\"  value='".$childname."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">age  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[age]\"  value='".$age."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">parent name  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[parentname]\"  value='".$parentname."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">email address  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[email]\"  value='".$email."'/></td>"; print "<td colspan=\"3\"><p> </p><p> </p></td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"3\" align=\"right\" height=\"30\">contact number  </td>"; print "<td colspan=\"2\" align=\"left\"><input type=\"text\" name=\"textfield[contactno]\"  value='".$contactno."'/></td>"; print "<td colspan=\"3\"> </td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"8\" height=\"30\"> </td>"; print "</tr>"; print "<tr>"; print "<td height=\"15\" colspan=\"2\"> </td>"; print "<td colspan=\"3\" align=\"right\">  </strong>check box if  member   ninja!</td>"; print "<td align=\"center\"><input type=\"checkbox\" name=\"checkbox[ninja]\"  value='".$ninja."' /></td>"; print "<td colspan=\"2\"> </td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"8\" height=\"30\"> </td>";  print "</tr>"; print "<tr>"; print "<td height=\"15\" colspan=\"2\"> </td>"; print "<td colspan=\"4\" align=\"center\">which subjects has member attended?</td>"; print "<td colspan=\"2\"></td>"; print "</tr>"; print "<tr>"; print "<td height=\"5\" colspan=\"8\"> </td>"; print "</tr>"; print "<tr>"; print "<td height=\"15\"> </td>"; print "<td colspan=\"2\" align=\"center\">scratch</td>"; print "<td colspan=\"2\" align=\"center\">app inventor</td>"; print "<td colspan=\"2\" align=\"center\">html</td>"; print "<td> </td>"; print "</tr>"; print "<tr>"; print "<td height=\"15\"> </td>"; print "<td colspan=\"2\" align=\"center\"><input type=\"checkbox\"  name=\"checkbox[scratch]\"  value='".$scratch."' /></td>"; print "<td  colspan=\"2\" align=\"center\"><input type=\"checkbox\"  name=\"checkbox[appinventor] \" value='".$appinventor."' /></td>"; print "<td colspan=\"2\" align=\"center\"><input type=\"checkbox\"  name=\"checkbox[html]\"    value='".$html."' /></td>"; print "<td> </td>"; print "</tr>"; print "<tr>"; print "<td><input type=hidden name=id value=".$id."><br></td>"; print "<td colspan=\"4\" align=\"center\"><input type=submit  value=' save '></td></form>"; print "<td td colspan=\"4\" align=\"center\"><form method='post' name='cancel'   action='memberinfo.php?id=".$id."'><input type='submit' value=' cancel '></form></td>"; print "</tr>"; print "</table>";  }  }  ?> i hope can help! i've gotten great here before , beginner php. please forgive typos or errors.
i need able display record entered, go in, edit , save updated record db. in advance...
 
 
  
Comments
Post a Comment