Am currently working on a PHP project..and am stuck with the calculation part and sending the results to my database table, am dealing with checkbox and my task is to allow members to tick all the suitable times and then to send each column to their table in my database then calculating all the columns there.. well I created the checkbox form and I know I need to use that name in the calculation but am not sure how to calculate each column in the checkbox and send the results to the table in the database then do all the addition from taking the results sent to the database...

Hope I can get some help with this and if it is possible refer me to a relevant tutorial

Cheers,

<form method="post">
      <input TYPE="checkbox" NAME="Saturday" VALUE="1" 
      <input TYPE="checkbox" NAME="Monday" VALUE="2" 
      <input type="submit" name="Calculate" value"Submit ">
      <form>

Recommended Answers

All 6 Replies

Not too sure what type of "Calculation" you are looking to do but in any case it's not difficult.

<form method="post" action="some_page.php"> // assign a page the form will submit to, it can the same page or a different one. 
<input TYPE="checkbox" NAME="Saturday" VALUE="1" >
<input TYPE="checkbox" NAME="Monday" VALUE="2" >
<input type="submit" name="Calculate" value="Submit ">
</form>

some_page.php

$sat=$_POST['Saturday'];
$mon=$_POST['Monday'];

$total = $sat + $mon; // $total would = 3 in this case.

Inserting data into the db is just as easy ... google it and there are countless sites that will show you how.

Member Avatar for diafol

I smell a homework assignment!? What's the calculation?

This is how I would probably do the calculation:

<form method="post" action="some_page.php"> // assign a page the form will submit to, it can the same page or a different one. 
<input TYPE="checkbox" NAME="days[]" VALUE="1" > Sunday
<input TYPE="checkbox" NAME="days[]" VALUE="2" > Monday
<input TYPE="checkbox" NAME="days[]" VALUE="3" > Tuesday
<input TYPE="checkbox" NAME="days[]" VALUE="4" > Wednesday
<input TYPE="checkbox" NAME="days[]" VALUE="5" > Thursday
<input TYPE="checkbox" NAME="days[]" VALUE="6" > Friday
<input TYPE="checkbox" NAME="days[]" VALUE="7" > Saturday
<input type="submit" name="Calculate" value="Submit ">
</form>

Then all you need to do to calculate is

$total = 0;
if(isset($_POST['days']) && is_array($_POST['days']) && count($_POST['days']) > 0)
{
      $total = array_sum($_POST['days']);
}

Thanks for your replys really appreaciated and it helped me to understand the idea but when I said calculations I meant I need to know which box every member selected then I'll pick the most selceted one , am not going to da addition or anything, I just need to find out the most selceted ones.. and am struggling in finding out the ones everymember selected and they can select more than one,.

Thanks for any help I get,

Cheers,

Am not looking for my homework to be done for me , my project is way big for anyone to do it for me.I joined this forum to get assistant from the members and thats what forum is about.. am just a new programmer and I need tips and am sure am capable of doing the project on my own , once I understand the main ideas for the problem..
Just clarifying.

Reply to ardav..

This is what I got so far but its not working any help??
I need to check the box they ticked then add it to the database and I need to know which one they ticked, do I need a special id for each checkbox to know exactly which box they ticked..


Cheers,

<form method="post">
      <input TYPE="checkbox" NAME="days[] />
      <input TYPE="checkbox" NAME="dasy[]" />
      <input type="submit" name="Calculate" value"Submit ">
      <form>



<?php

      for days ( $_POST['days']=='On')

      {
  
      if (days[] == 'On')
  $insert = "INSERT INTO mytable(pick)
VALUES ('".$_POST['days'].")";
    $add_mytable= mysql_query($insert);
      }

      ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.