learningcurve Posted March 8, 2012 Share Posted March 8, 2012 Hi, I am fairly new and I am modifying code someone else wrote. I believe this to be a simple solution question, but I can't figure it out. I have a form that passes data to an mysql table. I have this value set: $binderdiscount= 25; In the form, I added this checkbox: <td><input type="checkbox" name="binderdiscount" value="Yes" <?php if ($pgdata['binderdiscount']=='Yes') echo 'checked'; ?> />I do not need a Lilly Conference binder ($25 discount);</td></tr></table> It puts a yes into a cell in the mysql table. The problem is that I also want the price of 25 to appear in another cell of the mysql table IF the checkbox is checked. Otherwise, I want the value to be zero. I have written this line, but it doesn't seem to put anything in the table - let alone 25. <input type="hidden" name="binder_discount" value="<?php if (binderdiscount.checked==true) echo $binderdiscount; else echo '0';?>"> I feel like I am missing something very obvious, but I can't get it. Quote Link to comment https://forums.phpfreaks.com/topic/258557-mysql-data-not-posting/ Share on other sites More sharing options...
q11we Posted March 9, 2012 Share Posted March 9, 2012 I think you're confusing this with javascript code. to check if checkbox is checked using php, use if($_POST['binderdiscount']=='Yes') echo $binderdiscount; else echo '0'; But actually using javascript could be better, if both of the inputs are on same page <script> if([formname].binderdiscount.checked) {[formname].binder_discount.value=25;} </script> Quote Link to comment https://forums.phpfreaks.com/topic/258557-mysql-data-not-posting/#findComment-1325454 Share on other sites More sharing options...
learningcurve Posted March 12, 2012 Author Share Posted March 12, 2012 Thanks for the help. Unfortunately neither of these solutions worked. To help clarify a little, there are several pages involved: one contains all the javascript needed for the form, the actual form.php and one page that pulls in the javascript and the form pages and adds formatting and additional text. This is a very complicate setup and it has me baffled. Quote Link to comment https://forums.phpfreaks.com/topic/258557-mysql-data-not-posting/#findComment-1326493 Share on other sites More sharing options...
learningcurve Posted March 13, 2012 Author Share Posted March 13, 2012 Thank you so much!! It wasn't working this morning, but did some more thinking and some research based on your script and how other things on the javascript page were written. I am very happy to report it is now working!! Quote Link to comment https://forums.phpfreaks.com/topic/258557-mysql-data-not-posting/#findComment-1327018 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.