redarrow Posted May 19, 2006 Share Posted May 19, 2006 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.[code]<?phpswitch ($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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9980-how-to-use-switch-and-form/ Share on other sites More sharing options...
.josh Posted May 19, 2006 Share Posted May 19, 2006 [code]<?phpif ($_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>[/code]although... all you have to do instead of the switch here is if($_GET['blah']) { echo "num is " . $_GET['blah']; } Quote Link to comment https://forums.phpfreaks.com/topic/9980-how-to-use-switch-and-form/#findComment-37084 Share on other sites More sharing options...
redarrow Posted May 19, 2006 Author Share Posted May 19, 2006 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.[code]<?phpif ($_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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9980-how-to-use-switch-and-form/#findComment-37088 Share on other sites More sharing options...
.josh Posted May 19, 2006 Share Posted May 19, 2006 okay check it:[code]<?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;?>[/code]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[ ] browsesubmitif you do this:[ ] browse[ ] browse[ file ] browsesubmitit will not work. if you do this:[ file1 ] browse[ ] browse[ file2 ] browsesubmitthe file1 will upload, but file2 will not. you have to do this:[ file1 ] browse[ file2 ] browse[ ] browsesubmit 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. Quote Link to comment https://forums.phpfreaks.com/topic/9980-how-to-use-switch-and-form/#findComment-37091 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.