|
-
Jul 13th, 2009, 08:46 AM
#1
Thread Starter
Addicted Member
[RESOLVED] $_REQUEST then $_GET??
I'm recording numbers on my database using a textfield, $_REQUEST and $_GET commands.
I have this code
PHP Code:
if(isset($_REQUEST['Cost']))
$each_cost=$_REQUEST['Cost']; //array of costs entered
else if(isset($_GET['Cost']))
$each_cost=$_GET['Cost'];
The inputed cost is recorded in the URL string and called on later when adding multiple elements to my database.
PHP Code:
foreach($each_cost as $key => $value){ $cost_string = $cost_string."&Cost[$key]=".$value; }
I'm finding that saving the '$cost_string' requires me to refresh the current page twice for the string to record the entered number correctly?
Any idear why?
I've noticed that the 'Cost' (in the URL) only appears after I've refreshed the page twice but I've also used the $_REQUEST function and It still isn't working?
-
Jul 13th, 2009, 05:56 PM
#2
Hyperactive Member
Re: $_REQUEST then $_GET??
I think that you will need to show more code to find out why. You might want to check that you are getting the value of it before you are trying to use it. Can you show more code?
If I helped you please rate me.
-
Jul 13th, 2009, 06:24 PM
#3
Re: $_REQUEST then $_GET??
why are you using the $_REQUEST global? $_REQUEST combines the get/post/cookie variables. I'm not sure why you would do this logically -- if $_GET['cost'] is set, then $_REQUEST['cost'] is set. if you're not posting to this script, then using that global isn't really going to change anything. if you are, then you only need to check if $_REQUEST['cost'] is set at all. otherwise, I'd suggest being specific and use the right array; either $_POST, $_GET or $_COOKIE.
anyway! it does sound like you might need to post a little more code. I can't see what's wrong with the lines you posted.
-
Jul 14th, 2009, 02:24 AM
#4
Thread Starter
Addicted Member
Re: $_REQUEST then $_GET??
text field...
PHP Code:
<form name="myform" method="post" action="<?php $Costno // amount of text fields. $no=0; while($no<$Costno){ echo "&Cost[$no]=$costtotal[$no]"; $no++;} ?>" > <input name="Cost[<?Php echo "$key"; ?>]" type="text" value="<?php echo "$each_cost[$key]"; ?>" size="5" /></form>
submit button...
HTML Code:
<form method="post" >
<input name="Save" type="submit" class="box" value="Save" />
</form>
calculate and show results
PHP Code:
<?php echo "£".array_sum($costtotal); ?>
reconstruct URL string and save.
PHP Code:
foreach($each_cost as $key => $value){ $cost_string = $cost_string."&Cost[$key]=".$value; }
if ($_POST['Save']){ mysql_select_db("Sums", $con);
mysql_query("INSERT INTO DB (Cost) VALUES ($cost_string)");
-
Jul 14th, 2009, 03:17 PM
#5
Re: $_REQUEST then $_GET??
foregoing some small problems I see with your script, it looks like it'd be way easier for you to just submit your "cost" form via GET instead of POST. you're submitting a form via POST with a GET request as the action, and you want the values of that form in the GET array. why bother doing the work? let PHP do that for you.
PHP Code:
<form method="get" action="this_script.php"> <?php for($i = 0; $i < 3; $i++): ?> <input type="text" name="cost[<?php echo $i; ?>]" value="<?php echo htmlentities($_GET['cost'][$i]); ?>" /> <?php endfor; ?> <input type="submit" value="sum values" /> </form>
this will populate your URL correctly, and will correctly re-populate it every submission. then, you can reconstruct it later on.
also, if you're not going to be manipulating the URL later on (and don't have your array filled with a bunch of other stuff) and just need to save the entire query string, you could simple store $cost_string like this:
PHP Code:
$cost_string = $_SERVER['QUERY_STRING'];
-
Jul 15th, 2009, 05:59 AM
#6
Thread Starter
Addicted Member
Re: $_REQUEST then $_GET??
Changing the form from POST to GET would make life easyer but I am using the URL for other stuff! how can I add the form information to whats in the URL already?
-
Jul 15th, 2009, 03:18 PM
#7
Re: $_REQUEST then $_GET??
you could loop through the contents of GET and make hidden inputs if you want.
PHP Code:
<?php foreach($_GET as $key => $value): if($key == "cost") continue; //skip "cost" ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo htmlentities($value); ?>" /> <?php endforeach; ?>
this should do basically what you're looking for. though, it won't help if you have other arrays in your URL, but you could use a modified method of this.
-
Jul 15th, 2009, 06:00 PM
#8
Re: $_REQUEST then $_GET??
Just wondering, why are you using GET?
I know there are cases in which GET is a better options, but most of the times you can do the same with POST.
Delete it. They just clutter threads anyway.
-
Jul 20th, 2009, 02:43 AM
#9
Thread Starter
Addicted Member
Re: $_REQUEST then $_GET??
I find that using the code produces '%3D' and '%26' in the URL. How can I remove these?
-
Jul 20th, 2009, 02:52 AM
#10
Re: $_REQUEST then $_GET??
 Originally Posted by LingoOutsider
I find that using the code produces '%3D' and '%26' in the URL. How can I remove these?
Which code are you using?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jul 20th, 2009, 03:08 AM
#11
Thread Starter
Addicted Member
Re: $_REQUEST then $_GET??
Sorry my error its working now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|