472,334 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

How to keep $_POST variable into array format.

For example i have two files one in index.php & another is check.php.
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form id="form1" name="form1" method="post" action="check.php?id=tbl1">
  3.   <table width="200" border="1">
  4.     <tr>
  5.       <td colspan="2">Pesonal Info Table 1 </td>
  6.     </tr>
  7.     <tr>
  8.       <td width="72">Name:</td>
  9.       <td width="112"><input name="name" type="text" id="name" value="Ashok" /></td>
  10.     </tr>
  11.     <tr>
  12.       <td>Address</td>
  13.       <td><input name="address" type="text" id="address" value="Kathmandu" /></td>
  14.     </tr>
  15.     <tr>
  16.       <td><input name="tbl1" type="submit" id="tbl1" value="Submit" /></td>
  17.       <td><input type="reset" name="Submit2" value="Reset" /></td>
  18.     </tr>
  19.   </table>
  20. </form>
  21. </br>
  22. </br>
  23. <form id="form3" name="form3" method="post" action="check.php?id=tbl2">
  24.   <table width="216" border="1">
  25.     <tr>
  26.       <td colspan="2">Personal Info Table 3 </td>
  27.     </tr>
  28.     <tr>
  29.       <td width="56">Phone</td>
  30.       <td width="144"><input name="phone" type="text" id="phone" value="9841614320" /></td>
  31.     </tr>
  32.     <tr>
  33.       <td>Email</td>
  34.       <td><input name="email" type="text" id="email" value="alok_in1@yahoo.com" /></td>
  35.     </tr>
  36.     <tr>
  37.       <td><input name="tbl2" type="submit" id="tbl2" value="Submit" /></td>
  38.       <td><input type="reset" name="Submit6" value="Reset" /></td>
  39.     </tr>
  40.   </table>
  41. </form>
  42. </body>
& Second is check.php
Expand|Select|Wrap|Line Numbers
  1. foreach($_POST as $key=>$value)
  2.         { 
  3.         //echo "</br>";
  4.         $key.":".$$key=$value;
  5.         //echo "</br>".$key;
  6.         }
So the problem is that, when we fetch the data from $_POST method. how to keep the key & value variable into different array.
Expand|Select|Wrap|Line Numbers
  1. $field=array('name,'address ',......');
  2.                           & 
  3. $value=array('Ashok','Kathmandu','... '); 
Thank you.
Jul 27 '09 #1
16 6385
126 100+
Expand|Select|Wrap|Line Numbers
  1. $KeysArray = array_keys($_POST);
  2. $ValuesArray = array_values($_POST);
You mean this?
Jul 27 '09 #2
ya sir,

In the above code i am trying to fetch the table name through browser by using $_GET method.
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="form1" method="post" action="check.php?id=tbl1">
& Field & Values from $_POST.

Now I want. the table name is also fetch from $_POST & table fields & values also fetch from $_POST. so how can i pass the table name from index page.

And last
Expand|Select|Wrap|Line Numbers
  1. $KeysArray = array_keys($_POST); 
  2. $ValuesArray = array_values($_POST); 
It works but how to ingnore the last value of key & values. Because it is not necesssary for insert the database.

Jul 27 '09 #3
8,658 Expert Mod 8TB
if you know the index you can unset it. or (and to make it more secure) use PHP Filters to sanitize the post data.
Jul 27 '09 #4
& how can i ignore the last key & value of $_POST variable.
Jul 27 '09 #5
6,050 Expert 4TB
array_pop() it off?
Jul 27 '09 #6
Thank You Markus. .
Jul 27 '09 #7
8,658 Expert Mod 8TB
do you have proof that you actually need to remove the last key & value?
Jul 27 '09 #8
ya because the the last value & key are not used for insert the database.
Jul 28 '09 #9
8,658 Expert Mod 8TB
that's the reason, but is it proof?
Jul 28 '09 #10
I don't understand what do say sir? but..

There are differend form on main page. & I want to insert data from different form through one InsertData() function. So i need to pass the value & key of $_POST variable to insert function.

Thank you.
Jul 28 '09 #11
8,658 Expert Mod 8TB
I'm just saying that the POST array may look different depending on the circumstances. maybe a user agent sends you the POST array ordered or reversed or scrambled. therefore the last key/value pair is not necessarily the same in every circumstance.
Jul 28 '09 #12
Dheeraj Joshi
1,123 Expert 1GB
Yes.. I think we simply cant avoid the last element in the array..

Sometime back i too got some problems.

To avoid few parameters going into database we just checked all parameter then added it to DB.

Last element is not always what we expected.
Jul 29 '09 #13
then what i do? .
Jul 29 '09 #14
8,658 Expert Mod 8TB
if you know, what key it is you can unset it (or the other way round, if you know all other keys you can apply a filter to only preserve those)
Jul 29 '09 #15
126 100+
Or, on the client side, remove them before you submit...
Jul 29 '09 #16
Dheeraj Joshi
1,123 Expert 1GB
Its your choice.

Either go for client side or go for server side. Proceed as per your requirement.
Jul 29 '09 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

by: AJ Z | last post by:
I am using in_array() to search for a value ("other"), in order to validate a form. If I pass $_POST as the array to search PHP says that it is an...
by: Jack | last post by:
How would I add a variable that I will assign to a list of $_POST variables that I extract from a form? My form passes a value for $q. That works...
by: Quinonez | last post by:
if i set a $_SESSION=$_POST in every page of a multiple page form how then would i call it on a later page of the same session? and also how is...
by: EOZyo | last post by:
Hi, i'm trying to set pagination for a search i run on my website, i'll try to explain the easiest i can: When i click the search button on...
by: zorro | last post by:
greetings... I'm wondering what more advanced coders would think ot this: $_POST = clean($_POST); and now I can use POST directly: $sql=...
by: comp.lang.php | last post by:
I have no idea why this is happening and I need someone to explain this to me at the simplest level absolutely possible (pretend I'm a 10-year old...
by: Mason Barge | last post by:
I have a standard POST form consisting of two types of input: text input and textarea. The form downloads current settings from a mysql database. ...
by: lawpoop | last post by:
Hello all - Is there a way to get a nested array in a $_POST variable? I have a form where there are several questions, each one corresponding...
by: Bill H | last post by:
I wouldn't consider myself a newbie to PHP since I have never written one line of code in it (am a perl guy myself), but part of a team I am...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.