Jump to content

I'm beginner and I have question about the form


pro

Recommended Posts

Hi everybody,

sorry, I have silly question because I'm still beginner in php programming and sorry for my bad English  :-[

my question is:

for example,I have an HTML form

[code]
<html>
<body>

<form method="post" action="x.php">

<h3> variable1 </h3>

<input type="checkbox" name="cc" value ="on" />

<h3> variable2 </h3>

<input type="checkbox" name="cc" value ="on" />

<BR />

<input type="submit" value="send" />

</form>

</body>
</html>

[/code]

and i want to add a values to variable 1 and 2 (numbers) that will be calculated on the php code (x.php)

for example when you check on variable1 and variable2 and then depress send, the result should be a  calculation of these variables

how i can do that on the php code?

i hope you understand me  :-[

Link to comment
Share on other sites

Well if I am understanding you correctly it would be something like this..

[code]
<?php
$num = $_POST;
$res = $cc + $cc1;
echo $res;
?>
[/code]

Also -- you might make your check boxes named different...  otherwise they will overwrite each other...
Link to comment
Share on other sites

// thanx  radar and mort  for reminde me, I fogot to change the names :)

// Crayon, in this time I have to specify numbers for the check books?!


I will add more to my question

if I add two more checkbox on the HTML file and I want for evryone a number

for example

cc1 = 2

cc2 = 3

cc3 = 4

cc4 = 5

and i want to choose 2 or 3 of them randomly


where i heve to add these values so that next i will use (IF) function


\\ Crayon>>

\\ in this time there is no problem for the default value of "on" ?right?
Link to comment
Share on other sites

Well you see the value submits what is passed through to the php script.. so if each one has a value of on -- then when you take cc1 + cc2 you are going to either get an error or get onon which probably isnt what you want...

So if you decide you want to add 2 more check boxes you would do something like this..  first off have the value of checkbox the number you want them to equal...

I am working on a code that will allow you to add as many check boxes as you would like.
Link to comment
Share on other sites

Okay -- I was going to do a large setup using arrays and stuff from the form to determine how many were selected, etc..  though at this time i am brain dead so this will have to work...

[code]
<?php
if (!$_POST) {
print_r ($_POST);
echo "error";
} else {
if ($_POST[checkbox] ) {
$checkbox = $_POST[checkbox];
}
if ($_POST[checkbox2] ) {
$checkbox2 = $_POST[checkbox2];
}
if ($_POST[checkbox3] ) {
$checkbox3 = $_POST[checkbox3];
}
if ($_POST[checkbox4] ) {
$checkbox4 = $_POST[checkbox4];
}
}
echo (($checkbox) + ($checkbox2) + ($checkbox3) + ($checkbox4));
?>
[/code]

Now one thing I was having trouble with is i named my check boxes cc, cc2, cc3 and cc4.. though when i typed this..

print_r ($_POST);

it gave me the name as checkbox -- so at the beginning of your processing script I would add the print_r line i just typed and see what it puts your name as..  after that just put whatever that is into the code and it should work..  take if statements out if need to or add some in...  if you add any in you'll have to add them into the echo field as well with () around them...
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.