Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2005, 09:00 AM
Authorized User
 
Join Date: Dec 2004
Location: , , United Kingdom.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem using $_POST

Hi guys,

Just wondering if there is a way to insert a variable into the global variable $_POST?

For example:

$_POST[$var]

Cheers for any help in advance.

 
Old June 4th, 2005, 12:58 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

What?!

 
Old June 4th, 2005, 07:08 AM
Authorized User
 
Join Date: Dec 2004
Location: , , United Kingdom.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok maybe I was too vague.

I have a form with a text field but the name of text field is created from a variable eg...

<input type="text" name=<?=$i?> class="text">

And I want to pass this form data to a mysql statement using the $_POST method eg...

UPDATE playerPoints SET week1 = '" . $_POST[$i] . "' WHERE player_id = 2

But this does not work as $_POST does not seem to pick up the variable $i.

Its quite complicated and hard to explain.

 
Old June 4th, 2005, 07:52 AM
Authorized User
 
Join Date: Apr 2005
Location: Pune, MH, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jmukesh Send a message via Yahoo to jmukesh
Default

Hi gkirk,

Let me summarize things for you.

You have some form elements the name of which you
are generating on the fly. (Dynamically !).
You should be trying the same logic you provide
to build up the name and access the variable
when the from is submitted.

Well this thing will help you debug a bit.
print the whole request array.
<?
echo "Request";
print_r($_REQUEST);
echo "Get";
print_r($_GET);
echo "Post";
print_r($_POST);
?>

This will help you check whether you are reciving the variables
in your script.

Regards
Mukesh.:D


 
Old June 5th, 2005, 06:00 AM
Authorized User
 
Join Date: Dec 2004
Location: , , United Kingdom.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi jmukesh,

Thanks for your reply.

Ok so I am receiving the variables but now I need to insert these values into my sql statement and this is what I am having a problem with.

The name of the form I am posting is a variable named $i so in theory to access this using $_POST I should use $_POST[$i] but this does not work???

 
Old June 6th, 2005, 01:27 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

>> so I am receiving the variables

May be you store these into some other variables before writing $query
$_POST[] is an array of $_POST[0], $_POST[1] etc.
And this may be a reason for error if you are using $i as 0, 1, 2..

loop through $_POST[] and store into another array ppoints[]
( you are getting the POST[], note that if you are starting from $i=0,1,2.., your initial $_POST[$i] may not be $_POST[0] since $_POST[] is an array and there may be some FORM variables before you wrote name=<?=$i?> in FORM, so another idea is to write name=<?='abc'.$i?>

UPDATE playerPoints SET week1='ppoints[$i]' WHERE player_id=2

I hope u'll resolve:)
http://www.mediasworks.com/

 
Old June 6th, 2005, 08:42 AM
Authorized User
 
Join Date: Dec 2004
Location: , , United Kingdom.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have resolved the problem using a for each loop on the $_POST array.

Thanks for all your help:D

 
Old August 30th, 2006, 07:21 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to alexyyw
Default

Quote:
quote:Originally posted by gkirk
 I have resolved the problem using a for each loop on the $_POST array.

Thanks for all your help:D

Kirk

I'm having the same problem as well. Do you mind sharing your solution?





Similar Threads
Thread Thread Starter Forum Replies Last Post
isset($_POST) summi_beniwal Beginning PHP 1 June 21st, 2008 07:13 AM
$_POST PROBLEM karlirvin PHP How-To 1 December 16th, 2005 03:14 AM
Chapter 12 - $_POST['redirect'] problem cshu BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 4 July 25th, 2005 08:14 PM
Getting nothing from $_POST['varName']; Kalisan Beginning PHP 10 February 3rd, 2005 02:37 PM
$_POST Problem czambran BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 7 July 7th, 2004 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.