Jump to content


Photo

how to use switch and form


  • Please log in to reply
3 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 May 2006 - 05:14 AM

How do i get the form to $_GET the case 1 ect from the form cheers.


What ever number the user presses the ansaw comes from the case.

<?php


switch ($number_of_ansaws) {


case 1;
echo" num is 1";
break;

case 2;
echo" num is 2";
break;

case 3;
echo"num is 3";
break;

case 4;
echo"num is 4";
break;

case 5;
echo"num is 5";
break;


default:

break;

}

?>

<form action"" method="$_GET">
<input type="radio" name="1">ansaw 1
<br>
<input type="radio" name="2" >ansaw 2
<br>
<input type="radio" name="3">ansaw 3
<br>
<input type="radio" name="4">ansaw 4
<br>
<input type="radio" name="5">ansaw 5

<input type="submit" value="ansaw">
</form>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 May 2006 - 05:25 AM

<?php
if ($_GET['blah']) {
switch ($_GET['blah']) {
case 1: echo" num is 1"; break;
case 2: echo" num is 2"; break;
case 3: echo"num is 3"; break;
case 4: echo"num is 4"; break;
case 5: echo"num is 5"; break;
}
}
?>

<form action"<?=$PHP_SELF; ?>" method="GET">
<input type="radio" name="blah" value="1">ansaw 1
<br>
<input type="radio" name="blah" value="2">ansaw 2
<br>
<input type="radio" name="blah" value="3">ansaw 3
<br>
<input type="radio" name="blah" value="4">ansaw 4
<br>
<input type="radio" name="blah" value="5">ansaw 5

<input type="submit" value="ansaw">
</form>


although... all you have to do instead of the switch here is

if($_GET['blah']) { echo "num is " . $_GET['blah']; }
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 May 2006 - 05:53 AM

I was trying to make the form so if a user wanted to upload 5 files then they get 5 upload browse buttons and a send button.

Then they can send there 5 files but it dosent work on using the $GET statement as the form for sending the file info mucks it up.

Crayon Violent thank you for your time.
example.
A user goto a page and the page says how many files to upload and then the boxs come up and then the user can use the boxs for uploading the files and then send that information to a result page to go into the database and valadate but all php.



<?php
if ($_GET['blah']) {
switch ($_GET['blah']) {


case 1: echo"

<input type='file' name='file1'>
<br>
<input type='submit' value='send'><br>";
 break;





case 2: echo" 
<form>
<input type='file' name='file1'>
<br>
<input type='file' name='file2'>
<br>
<input type='submit' value='send'>
<br>"; 
break;



case 3: echo"<form>
<input type='file' name='file1'>
<br>
<input type='file' name='file1'>
<br>
<input type='file' name='file2'>
<br>
<input type='submit' value='send'>

<br>";
 break;





case 4: echo"<form>
<input type='file' name='file1'>
<br>
<input type='file' name='file1'>
<br>
<input type='file' name='file1'>
<br>
<input type='file' name='file2'>

<input type='submit' value='send'>

<br>"; break;





case 5: echo"<form>
<input type='file' name='file1'>
<br>
<input type='file' name='file1'>
<br>
<input type='file' name='file1'>
<br>
<input type='file' name='file1'>
<br>
<input type='file' name='file2'>
<br>
<input type='submit' value='send'>
"; 
break;
}
}
?>

<form action"<?=$PHP_SELF; ?>" method="GET">
<input type="radio" name="blah" value="1">ansaw 1
<br>
<input type="radio" name="blah" value="2">ansaw 2
<br>
<input type="radio" name="blah" value="3">ansaw 3
<br>
<input type="radio" name="blah" value="4">ansaw 4
<br>
<input type="radio" name="blah" value="5">ansaw 5

<input type="submit" value="ansaw">
</form>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 May 2006 - 06:45 AM

okay check it:

<?php
   if (!$file) {
      $form = "select a file(s) to upload.<br>";
      $form.="<form action='$PHP_SELF' method='post' enctype='multipart/form-data'>";
      if (!$_GET['blah']) {
              $count = 1;
            } else { $count = $_GET['blah']; }
            for($x=0;$x<$count;$x++) {
               $form.="   <input type='file' name='file[]' size='50'><br>";
        }
            $form.="   <input type='submit' value='upload'>";
      $form.="</form>";
   } else {
    $x=0;
        $form =" ";
        while ($file[$x]) {
            copy ("$file[$x]","$file_name[$x]") or die("could not upload your file(s)");
      $form.="File upload succeeded...<br>";
      $form.="sent: ".$file_name[$x]."<br>";
      $form.="size: ".$file_size[$x]."<br>";
      $form.="type: ".$file_type[$x]."<br>";
            $form.="<br>";
    $x++;
   }
     }
   echo $form;
?>

this will make blah amount of text boxes depending on whatever myscript.php?blah=x is. so if you do myscript.php?blah=5 then it will show 5. if you put blah=10 it will do 10. blah=2 will be 2 and so on..

you can browse for all x files and click submit and it will upload all x. there is a small bug in the script that i'm too tired to work out though: example: if you put blah=3 it will show 3 input fields. but if you do not put the first file in the 1st box, 2nd file in the 2nd box, etc... then it will not work.

let's say you have 3 files you want to upload.

[ ] browse
[ ] browse
[ ] browse
submit

if you do this:
[ ] browse
[ ] browse
[ file ] browse
submit

it will not work.

if you do this:

[ file1 ] browse
[ ] browse
[ file2 ] browse
submit

the file1 will upload, but file2 will not.

you have to do this:

[ file1 ] browse
[ file2 ] browse
[ ] browse
submit

if you want it to work right. It's a minor bug, and if you plan on entering in 3 files when you do blah=3 then all the spaces will be filled, and the bug won't show up anyways. But i'm too tired to fix it. i'm sleepy and going to be now.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users