kaozdragon Posted July 11, 2007 Share Posted July 11, 2007 not quite too sure how to explain this but..i'll try the best i can with what i'm doing. i'm making a database (obviously) where i want the user to be able to register whether they want notifications with a checkbox. so how i did that is i made a checkbox that if it's checked it will return the value "Yes" to the db. now i want the user to be able to change that when they want. how do i make another page to retreive the checkbox already checked and if they want to update it, they can uncheck it and update it. thanks in advance and i hope this is clear enough. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted July 11, 2007 Share Posted July 11, 2007 You'd just need to create a query that updates that from Yes to No (assuming that's the choices). // set a variable for their id that's passed through the URL $id = $_GET['id']; $sql = "UPDATE tablename SET columnname WHERE id='$id' This assumes that you provide them a simple form that passes their id through. Quote Link to comment Share on other sites More sharing options...
marcus Posted July 11, 2007 Share Posted July 11, 2007 <input type="checkbox" name="name" value="1"> If the box is checked, the value is 1, if it's not checked it will have no value. If the value is stored in your database, just select it, say if the value in the database equaled one then the box would be checked: $sql = "SELECT * FROM `tbl_name` WHERE `value`= 'value'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); if($row[name] == 1){ $check = " CHECKED"; }else { $check = ""; } echo "<input type=\"checkbox\" name=\"name\" value=\"1\"$check>\n"; Then passing it: $name = $_POST['name']; if($name){ $sql = "SELECT * FROM `tbl_name` WHERE `value` ='value'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); if($name == $row[name]){ //no need to update }else { //update query } }else { //no update } Quote Link to comment Share on other sites More sharing options...
marcus Posted July 11, 2007 Share Posted July 11, 2007 Also if you were to have multiple checkboxes [say you were deleting pieces of mail] <input type="checkbox" name="mail[]" value="1"> <input type="checkbox" name="mail[]" value="2"> <input type="checkbox" name="mail[]" value="3"> <input type="checkbox" name="mail[]" value="4"> <input type="checkbox" name="mail[]" value="5"> Then: $mail = $_POST[mail]; if($mail){ echo "You selected:<br>\n"; foreach($mail AS $mailid){ echo $mailid . "<br>\n"; } }else { echo "No mail selected\n"; } Quote Link to comment Share on other sites More sharing options...
kaozdragon Posted July 11, 2007 Author Share Posted July 11, 2007 thanks a lot. i got it working and the replies were almost immediate. 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.