Jump to content

Recommended Posts

I'm trying to get it 1 for not checked and 0 for unchecked heres my code, btw what it does when you uncheck them, they just stay checked, eg when i try to make it 0 over 1, it just reverts to 0 and doesn't actually update it, although it gives no errors, just doesn't function correctly..:

 

 

<?php
if(isset($_GET['groupid'])) {
$group_id = $_GET['groupid'];
$group_query = mysql_query("SELECT * FROM userstructure WHERE id='$group_id'");
$group_row = mysql_fetch_array($group_query);

$Group_NamePost = $_POST['groupname'];
$DescriptionPost = $_POST['description'];
if(isset($_POST['editgroup'])) {
if(isset($_POST['Page_Manager'])) {
$Page_ManagerPost = "1";
} else {
$Page_ManagerPost = "0";
}
if(isset($_POST['Client_Manager'])) {
$Client_ManagerPost = "1";
} else {
$Client_ManagerPost = "0";
}
if(isset($_POST['News_Manager'])) {
$News_ManagerPost = "1";
} else {
$News_ManagerPost = "0";
}
if(isset($_POST['Upload_File'])) {
$Upload_FilePost = "1";
} else {
$Upload_FilePost = "0";
}
if(isset($_POST['Settings'])) {
$SettingsPost = "1";
} else {
$SettingsPost = "0";
}
if(isset($_POST['Access_Logs'])) {
$Access_LogsPost = "1";
} else {
$Access_LogsPost = "0";
}
if(isset($_POST['Profile'])) {
$ProfilePost = "1";
} else {
$ProfilePost = "0";
}
if(isset($_POST['User_Management'])) {
$User_ManagerPost = "1";
} else {
$User_ManagerPost = "0";
}
if(isset($_POST['Private_Messages'])) {
$Private_MessagesPost = "1";
} else {
$Private_MessagesPost = "0";
}
if(isset($_POST['Site_Navigation'])) {
$Site_NavigationPost = "1";
} else {
$Site_NavigationPost = "0";
}
if(isset($_POST['Testimonials_Manager'])) {
$Testimonials_ManagerPost = "1";
} else {
$Testimonials_ManagerPost = "0";
}
mysql_query("UPDATE userstructure SET name='$Group_NamePost', description='$DescriptionPost', pagemanager='$Page_ManagerPost', clientmanager='$Client_ManagerPost', newsmanager='$News_ManagerPost', uploadfile='$Upload_FilePost', settings='$SettingsPost', logs='$Access_LogsPost', profile='$ProfilePost', usermanagement='$User_ManagementPost', privatemessages='$Private_MessagesPost', sitenavigation='$Site_NavigationPost', testimonials='$Testimonials_ManagerPost' WHERE id='$group_id'") or die(mysql_error());
} else {
?>
<form method="post" name="editgroup" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<fieldset><legend>Group Name</legend>
<input type="text" name="groupname" value="<?php echo $group_row['name']; ?>" />
</fieldset>
<fieldset><legend>Description</legend>
<textarea name="description"><?php echo $group_row['description']; ?></textarea>
</fieldset>
<fieldset><legend>Access</legend>

<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="140">Page Manager</td>
    <td width="260"><input name="Page_Manager" type="checkbox" <?php if($group_row['pagemanager'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Client Manager</td>
    <td><input type="checkbox" name="Client_Manager" <?php if($group_row['clientmanager'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>News Manager</td>
    <td><input type="checkbox" name="News_Manager" <?php if($group_row['newsmanager'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Upload File</td>
    <td><input type="checkbox" name="Upload_File" <?php if($group_row['uploadfile'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Settings</td>
    <td><input type="checkbox" name="Settings" <?php if($group_row['settings'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Access Logs</td>
    <td><input type="checkbox" name="Access_Logs" <?php if($group_row['logs'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Profile</td>
    <td><input type="checkbox" name="Profile" <?php if($group_row['profile'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>User Management</td>
    <td><input type="checkbox" name="User_Management" <?php if($group_row['usermanagement'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Private Messages</td>
    <td><input type="checkbox" name="Private_Messages" <?php if($group_row['privatemessages'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Site Navigation</td>
    <td><input type="checkbox" name="Site_Navigation" <?php if($group_row['sitenavigation'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
  <tr>
    <td>Testimonials Manager</td>
    <td><input type="checkbox" name="Testimonials_Manager" <?php if($group_row['testimonials'] == '1') { echo "checked=\"checked\""; } ?>  /></td>
  </tr>
</table>
</fieldset>
<fieldset><legend>Submit</legend>
<input type="submit" name="editgroup" value="Edit Group" />
</fieldset>

</form>
<?php
} 
}
else {
$user_query = mysql_query("SELECT * FROM userstructure");
echo "<table cellspacing='4' cellpadding='2' border='0'>";
echo "<tr><th>User Group</th><th>Edit Group</th><th>Delete Group</th>";
while($user_row = mysql_fetch_array($user_query)) {
echo "<tr><td>";
echo $user_row['name'];
echo "</td><td><a href='groupmanagement.php?groupid=";
echo $user_row['id'];
echo "'>Edit</a>";
echo "</td><td><a href='deletegroup.php?groupid=";
echo $user_row['id'];
echo "'>Delete</a>";
echo "</td></tr>";
}
echo "</table>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/97909-checkbox-validation/
Share on other sites

I'm not sure what your really asking, but the way a checkbox works (with regards to POST data) is when its checked it will give the value you'd like, when its unchecked it is skipped al together, its ignored by php (as it never reaches it) and the POST data.

 

i.e.

<input name="Page_Manager" type="checkbox" <?php if($group_row['pagemanager'] == '1') { echo 'checked="checked'; } ?>  value="<?=$group_row['pagemanager']?>" />

 

this will set its value to your corresponding database value and tick it if the database value is set to '1'.

 

this should work (it does on my server), if your still n ot getting the result you wanted, try rephrasing your question and we'll gladly answer you again.

Link to comment
https://forums.phpfreaks.com/topic/97909-checkbox-validation/#findComment-500942
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.