Jump to content

mysql data not posting


Recommended Posts

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. 

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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. 

Link to comment
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.