php_guest Posted January 31, 2009 Share Posted January 31, 2009 Please could you help me with following problem: I have profile page with titles (age, country, gendre), values as text fields (23, France, ...) and check boxes for privacy setting. New titles can be added and text fields can be edited. See the image. I did so far everything, I just have no idea how to save into table if check box of each title was checked, so the value is yes. <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> <table> <tr><td style='text-align: left; font-weight: bold'> Title</td> <td style='text-align: left; font-weight: bold'>Value</td></tr> <tr><td><input type="text" name="title"</td> <td><input type="text" name="value"</td> <td><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <table> <?php echo " <tr> <td>Title</td><td>Value</td><td>Privacy</td> </tr>"; if (isset($_POST)) { foreach ($_POST as $key => $value ) { mysql_query ("UPDATE titles SET uValue = '$value' WHERE ID ='$key"); //this line is where I have problem mysql_query ("UPDATE titles SET uPrivacy = 'yes/no' WHERE ID ='$key'"); it is only yes or only no } } $query = "SELECT * FROM titles WHERE UserID = $ID"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo "<br /><b>Edit data:</b> <br /><br />"; while($row = mysql_fetch_assoc($result)) { extract ($row); echo " <tr> <td><b>$uTitle</b></td> <td><input type='text' name='$ID' value='$uValue'></td> <td><input type='checkbox' name='$uTitle' value='yes'> </tr>"; } ?> <tr><td><input type="submit" value="Update"></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/143256-solved-complicated-issue-with-submit-form/ Share on other sites More sharing options...
gaza165 Posted January 31, 2009 Share Posted January 31, 2009 Can you post the full code so we can see all the privacy check boxes?? Quote Link to comment https://forums.phpfreaks.com/topic/143256-solved-complicated-issue-with-submit-form/#findComment-751289 Share on other sites More sharing options...
php_guest Posted January 31, 2009 Author Share Posted January 31, 2009 this is all the code related to form. There can be 3 or more than 10 check boxes. It depends on how many titles user add. For each title there is one check box. Now I don't know how to save the value to the table so I can use it later to check which data user would like to lock. Quote Link to comment https://forums.phpfreaks.com/topic/143256-solved-complicated-issue-with-submit-form/#findComment-751364 Share on other sites More sharing options...
php_guest Posted February 1, 2009 Author Share Posted February 1, 2009 I see the problem is that I don't receive the value of $_POST[$uTitle]. I tested with inserting echo statement. If I uncomment the 8th line it doesn't echo anything. I have no idea why it doesn't echo $_POST[$uTitle]. Here is also the image of table for better explanation. <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <table> <?php echo " <tr> <td>Title</td><td>Value</td><td>Privacy</td> </tr>"; //echo $_POST[$uTitle]; if (isset($_POST)) { foreach ($_POST as $key => $value ) { mysql_query ("UPDATE titles SET uValue = '$value' WHERE ID ='$key'"); } } $query = "SELECT * FROM titles WHERE UserID = $ID"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo "<br /><b>Edit data:</b> <br /><br />"; while($row = mysql_fetch_assoc($result)) { extract ($row); echo " <tr> <td><b>$uTitle</b></td> <td><input type='text' name='$ID' value='$uValue'></td> <td><input type='checkbox' name='$uTitle' value='yes'> </tr>"; } ?> <tr><td><input type="submit" value="Update"></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/143256-solved-complicated-issue-with-submit-form/#findComment-751668 Share on other sites More sharing options...
php_guest Posted February 1, 2009 Author Share Posted February 1, 2009 I just solved the problem: if (isset($_POST)) { foreach ($_POST as $key => $value ) { if ($value=='yes' || $value=='no') { mysql_query ("UPDATE titles SET privacy='$value' WHERE uTitle='$key'"); } else { mysql_query ("UPDATE titles SET uValue = '$value' WHERE ID ='$key'"); } } } Quote Link to comment https://forums.phpfreaks.com/topic/143256-solved-complicated-issue-with-submit-form/#findComment-751886 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.