473,800 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to keep $_POST variable into array format.

luckysanj
69 New Member
For example i have two files one in index.php & another is check.php.
index.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>
  43.  
& 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.         }
  7.  
  8.  
So the problem is that, when we fetch the data from $_POST method. how to keep the key & value variable into different array.
like:
Expand|Select|Wrap|Line Numbers
  1. $field=array('name,'address ',......');
  2.                           & 
  3. $value=array('Ashok','Kathmandu','... '); 
Thank you.
Jul 27 '09 #1
16 6570
Canabeez
126 New Member
Expand|Select|Wrap|Line Numbers
  1. $KeysArray = array_keys($_POST);
  2. $ValuesArray = array_values($_POST);
You mean this?
Jul 27 '09 #2
luckysanj
69 New Member
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">
  2.  
& 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); 
  3.  
It works but how to ingnore the last value of key & values. Because it is not necesssary for insert the database.

Thanks
Jul 27 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
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
luckysanj
69 New Member
& how can i ignore the last key & value of $_POST variable.
Jul 27 '09 #5
Markus
6,050 Recognized Expert Expert
@luckysanj
array_pop() it off?
Jul 27 '09 #6
luckysanj
69 New Member
Thank You Markus. .
Jul 27 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
@luckysanj
do you have proof that you actually need to remove the last key & value?
Jul 27 '09 #8
luckysanj
69 New Member
ya because the the last value & key are not used for insert the database.
Jul 28 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
@luckysanj
that's the reason, but is it proof?
Jul 28 '09 #10

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

Similar topics

12
6014
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 invalid datatype. It is an array and if I copy it to another variable (i.e. $list = $_POST;) it works fine. The same is also true of implode(). Do you believe this is intended or is it a bug? --
10
2669
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 fine. What I want to do is run an if/else on it and assign a new variable based on what was chosen such as if ($q == "red") { $q = "tp"; //change $q to this value $sub = "ak"; //attach this value to the $sub variable } else {
9
6798
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 distigushed between pages ? should it be set up differently on each page, ive read of $_SESSION=$_POST but i cant seem to figure out how to call it back at the end of the form
10
7246
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 search.php, data is received and stored in variables within results.php, MySQL structure seems to work as expected, although i get some problems: As soon as i click on the "Page 2" Link, i get nothing, neither results nor page numbers.
15
7153
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= "select * from T1 where myvar='$_POST' " ;
6
1384
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 and explain it that way, please!) This class method: PHP Code: /** * Perform an array scan *
10
3018
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. The user can update the information by modifying the text and clicking a standard "submit" button. MAIN PROBLEM: My problem is that the information transmitted to the formhandler apparently has some sort of whitespace added to it. If I simply use trim() on the POST variable, it fails the...
7
5203
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 to a database row. On submission of the form, I loop through the $_POST array, and update the database appropriately. So my post variable looks like this:
32
8214
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 working with is writing some php interfaces into a database and I noticed that they are relaying on HTML form value names to always be lowercase in their code (ie $_POST (fyi that may be typed wrong)) and from my experience it is always better, when reading in the post information to convert the the...
0
9695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10514
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10287
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10042
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9099
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6826
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.