Efficiently & Safely (re)filling Array From $_POST
I'm using a single script to generate a table with <input>s in each row.
I fill the array with initial values, then write it out to the table
and let the user edit the values. Something like:
$myarray = $array(1, 2, 3, ... 100);
echo 'Enter your changes, then click Submit:'
foreach ($array as $i)
echo '<table tags> <input value="'.$i.'" name="index.'$i.'"> <table
tags>'
When the user clicks Submit, I need to pull the values back into the
array so I can re-display & operate on it. The data is in $_POST, which
is associative and contains stuff other than my array. $_POST contains
something like:
Submit=>submit
someVariable=>someValue
anotherVariable=>anotherValue
index1=>1
index2=>99
index3=>93.2
....
index100=>-3
After doing a quick google search, I tried:
for ($i = 0; $i < count($array); $i++)
{
$name = 'index'.$i;
$array[$i] = $_POST["$name"];
}
It runs, but I get nothing out of $_POST - those key values are unset.
Is my only option to inefficiently iterate through $_POST AND $myarray,
and doing the assignment to the proper element when I find the
corresponding name in $_POST's key?
Can I use the $_POST keys as indexes in a loop? If so, is it *safe* to
do that, and what's the syntax? Something vaguely like:
for ($i = 0, $key = index1; $i < 100 && $key < index100; $i++, $key++)
array[$i] = $_POST[$key];
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Filling An Array With A Set Of Values
i know there's a way to fill an array with a predetermined set of values (i.e. 0-999, a-z, etc) but i can't find the right syntax for the task nor find any examples.
Problem Filling An Array
I'm writing code to validate fields in a form before saving to a db. All the validating functions are in a separate script which is required. All the validating functions add an error message to an array if the data doesn't validate. I check if something went wrong with count($theArray). Here's my code:
Filling An Array Depending On A Variable
I want to fill an array with numbers depending on a variable. On the page for holiday booking, the user gives the date of arrival and the date of departure, now i have written code to determine the number of days the user is staying. Say this is 5, now i want to fill a variable with the numbers 1,2,3,4,5 If the user stays 3 days the variable should be filled with 1,2,3 I came up with this ....
Best Way To Learn PHP Fast And Efficiently?
I'm a beginner with PHP but am very familiar with the other scripting languages and web programming languages. Does anyone recommend a way so that I can learn/master PHP quickly?
$_POST=array();
In the text I am reading it says that $_POST = array(); will see to it that a form does not retain any values. That is understood. My question is what does this code normally do / in which context is this code normally used? I realize that this is an elementary question....
The $_POST Array
I got the following code: reset ($_POST); while (list($key,$val) = each($_POST)) { echo "$key => $val "; } But this prints out nothing. If I replace the code above with: print_r ($_POST); I can see the content of the $_POST array. Why?
$_POST Array Errors
I am having a problem with some code that uses $_POST, so I wrote the following code to debug the problem: $num = count($_POST); echo ($num); for ($idx=0; $idx < $num; ++$idx) { echo("$_POST[$idx] <br> "); } Notice: Undefined offset: 0 in C:InetpubwwwrootToDoListedittask.php on line 38 Notice: Undefined offset: 1 in C:InetpubwwwrootToDoListedittask.php on line 38 So there are clearly 8 elements in the array, which is what I expect, but for some reason I cannot access them?
Reading An Array Of $_POST
My forum is setup so it dynamically posts 1 or more direct deposits depending on how many the user enters. The problem is it is only writing the first $POST to mySQL and not the subsequent ones. Do I need to store all the same $_POSTS[same name] in an array or can I do a $_POST[same name] +new_Count. Can i do this without using arrays, how does the $_POST variables. Look at my psudeo code to see what I mean, the syntax is right at work, but this is the best I can remember at home. Code:
Storing Numeric Values Efficiently In A Text File
I need an efficient method for storing numeric values in text files. I want to minimize storage space and also need to have a method that supports fast writing and reading of such values to/from the file, while also making them available for PHP to use numerically. E.g. if I have a number like "173522", I _could_ write it out in the file as a string: 1, 7, 3, 5, 2 and 2. This would take 6 bytes. If I would need to access the number again, I would have to read the 6 bytes as a string with PHP and then PHP would automatically be able to treat it as a numeric (with some slight loss of time/performance for the conversion I guess). However, a method that I assume might be more efficient - but which I currently don't know how to implement - would be to convert the format of the number into a... I don't know what to call it. But I think you know what I mean. It would then take only 3 bytes of space when stored in the text file: 1 byte for numerals 1-255, 2 bytes for numerals 256-65536, etc. I wonder if there is a way to implement this latter method with PHP and if it would give better performance than the previous method. Right now, I have no idea of how to do it and would be grateful for any suggestions.
Globalizing $_POST Array Variables
I'm trying to come up with a function that will globalize each element in the $_POST array, effectively mimicking the php.ini 'Globals = On' setting for the $_POST array. So far I've created a minimal recursive function that takes an array as argument, parses each element in the array and checks if it's an array or not, if it is an array it's passed recursively back to the function, otherwise the element is made 'global'. The function looks like this:
Dynamic JS Form And $_POST Array
I have a form that I am altering after page load with javascript. Basically I have a button that inserts another text field into the form which the user can fill out. Its for a calendar, and I'm allowing them to optionally add multiple days for an event. Each box that is created has the same name with [] on the end to make it an array. When I view the post array with print_r($_POST), only the first textbox's value shows up. This is the only textbox in the form when the page loads. Simplified example: <form name="calform" action="process.php" method="post"> <input name="startday[]" type="text" class="bordered" size="25" /> <input type="button" onclick="add_one_more()" value="Add another date" /> // if the user hits the add button it adds this input field after pageload <input name="startday[]" type="text" class="bordered" size="25" /> </form> And here's what I'd get from that form Array ( [startday] => Array ( [0] => test1 )) A button inside the form basically adds another <input> tag between the <form> tags. Why isn't PHP seeing the data?
Checkboxes, $_POST Array, And Switch Statement
I'm having problems with a switch statement that is wrapped in a foreach statement so that each index in an array is evaluated against the switch statement. The switch/case will then return some output for display. I have a long list of classes for the upcoming semester. Each one has a checkbox to the right that has the following code. <input type="checkbox" name="course[]" value="i"> where i increases linearly with each class, i.e. first class value="1" second value="2". There are 41 classes for the semester. Upon submission of the form (Yes, I have a <form> tag with all the necessary parameters.), display.php (the action of the form) should loop through each key in the course array and evaluate the value against a switch statement. Here is what my PHP code looks like so far: if(isset($_POST['course']) { foreach ($_POST['course'] as $key => $value) { switch($value) case 1: echo 'foo' break; case 2: echo 'bar' break; default: echo 'Please select a course' break ............. I tried putting the case numbers in quotes like case "1": but that didn't make any different. What this will eventually do is pull book information for each class that is selected from Amazon and enable the user to quickly add the books to a shopping cart and check out. I shortened the code (leaving out the other 39 cases!) and I omitted the html that the PHP page contains. Can anyone explain what I am doing wrong with my switch statement and/or array?
Safely Deleting A Db Record With Php
I hope I'm not OT. I have the following issue: I want to delete a record from my db with a php script. Let's say I'm auth'd and I want to delete the record id 440. With a simple form (get or post), I send the id to my script and delete the record (DELETE FROM table WHERE id=some_validated_input). The problem is if I'm a nasty guy I just write my own form and delete any record I want (since I'm auth'd) by just sending another id. Is there any way to make arbitrary record deletion non-trivial in php? I'm thinking about a hash function to replace the real db id (DELETE FROM table WHERE record_hash=validated_form_hash), if possible without adding an awfull lot of server side computation.
How Does PHP5 Process POST Data In Creating $_POST Array?
I need to save a wav file that is HTTP POSTed to a php page. What does PHP5 do automatically to a POSTed variable when it puts it in the $_POST[] superglobal array? I haven't been able to find any info on this.... I have a script that does what I want in PERL, but I need to do it in PHP. I think the PERL does something magic when it does this: #### PERL CODE #### read ( STDIN, $buffer, $ENV { 'CONTENT_LENGTH' } ); @pairs = split ( /&/, $buffer ); foreach $pair ( @pairs ) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM { $name } = $value; } #### END PERL CODE ####
Safely Writing To The Server File System?
So my content-management-thing lets users upload images to go with their stories. Image metadata gets stored in MySQL, and the binaries themselves are written straight to the filesystem. Problem: my webmaster tells me it's a big security risk to grant the web user the 'write' privilege needed to write the images to the images directory. Question: is there an elegant solution to this, or is he overstating the risk? This model seems to be the one that is most recommended for storing images and other files. How do y'all do it?
Allowing Customers To Edit Their Web Pages Safely... How?
Do you actually let your customers modify any of the html / php pages on your websites? (mines all php due to tracking) Do you restrict access / hide code / protect certain areas from modification? I was planning on allowing access to non critical pages in a sub-directory then using the php copy command to move allowed pages to the main directory (which thay will have no access to). But when I start to think about dreamweaver templates and all the like, what a mess they could make of things, especially if editing without dreamweaver, ie. frontpage! So, how do you normally go about allowing customers to make minor changes themselves, i.e. basic text content.... or don't you... I had another idea of allowing editing in a familiar program like frontpage and automatically merging the body only into the main template... sounds like i'd be asking for trouble there. (I'm not ever going to consider frames, by the way!). The other idea was to allow modification of html text areas via the website, but that's another package to write.... Anyhow - what's the norm here, what do you do?
Safely Cut Off Short Preview Version Of Long String
Here`s a problem I have been working on for a while, but can`t seem to solve satisfactory. I have a database with blog entries. Because each of those entries has a variable length which can be quite long, I want to build an overview page. Of each entry there will be a preview version, say 700 characters max. My problem has to do with HTML tags. If for example an entry contains a <BLOCKQUOTE> with a large quote, my function would break off somewhere halfway in the quote. The end result of course won`t have the </BLOCKQUOTE>, rendering the resulting page horribly bad. I would like to build a function that breaks a string up to max X characters long, but plays it safe when it encounters any HTML tag: it does not matter if the end result is a string of say 670 characters long, it only matters that it approximates the max character setting and doesn`t mess up the HTML tags.
Repeated Filling
How do I fill up a form continously and submit it remotely? Meaning, the form info comes in from a dbase using php and gets submited to a remote site. All this happens automatically.
Zero Filling Integer
Is there a way in PHP to zero fill an integer to a specified length? For instance, if I have a two digit number, and I want to zero fill it to four digits, is there a PHP function I can use? Or do I manually have to add zeros to the front?
Filling Variables From SQL
I have a dynamic dropdown menu filled with names of people that posted to the guestbook. When I select a user I want info about that user to show up (ip, when posted...) if(in("show")) { $id = $_POST['info']; $action = "SELECT * FROM entried WHERE id = '$id'"; $result = mysql_query($action); $name_info = ??? $ip_info = ?? } How can I fill in those variables (name_info , ip_info ) with information from SQL (fields are name , ip ...)
Filling Out Forms Through Proxies With Php
i'm connecting to the internet via a proxy, and am having problems filling out forms... below is the code i have, and below that is the http request i am trying to make it look like. they look the same to me, but it isn't working, so i guess they aren't... $proxy = fsockopen("tcp://someaddresshere", 80, $errno, $errstr); $temp = "somethingelse=blablabla"; fputs($proxy,"GET somesite HTTP/1.0"); fputs($proxy,"Accept: */*"); fputs($proxy,"Referer: http://someothersitesite"); fputs($proxy,"Content-Type: application/x-www-form-urlencoded"); fputs($proxy,"Content-Length: " . strlen($temp) . ""); fputs($proxy,$temp . ""); while (!feof($proxy)) print fgets($proxy); fclose($proxy); with that script, i don't get anything. however, with this http request, from opera 7.10, i do: POST http://somesite HTTP/1.0 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.10 [en] Host: somesite Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1 Accept-Language: en;q=1.0 Accept-Charset: windows-1252, utf-8, utf-16, iso-8859-1;q=0.6, *;q=0.1 Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0 Referer: http://someothersite Proxy-Connection: close Content-type: application/x-www-form-urlencoded Content-length: xx somethingelse=blablablaHTTP/1.1 200 OK Via: 1.1 DELTANS Connection: close Content-Type: text/html Date: Fri, 20 Jun 2003 17:54:37 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.2 PHP/4.1.2 mod_perl/1.26 X-Powered-By: PHP/4.1.2 Set-Cookie: PHPSESSID=6c6baebea48c1ee4ad562d7fef3a46a4; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: something Set-Cookie: something now the last part of the http request isn't a request persay, but whatever,....
Form Filling PDF Template
I realise there is a lot written on this subject, but as a newcomer I'm not having much luck finding a solution to my particular problem. Grateful for your help! I need customers to be able to enter information into a form and receive a non-editable PDF document, by email and/or in the browser, containing that information (with a specific layout based on a template) after submitting the data. I have found numerous libraries like PDFkit etc that might well do this. I'm not sure if I can install the library onto my host server though - is it normal to be able to do this? There's also the Acrobat forms option. However, I need this to be fool proof. If the client does not currently have Acrobat reader installed on their computer, would they not be able to view the PDF form, thus limiting accessibility? I also want to avoid FDF if possible because it seems that, again, there's the potential for the browser not to open the file properly, or problems if the client doesn;t already have Acrobat reader installed.
Automated Table Filling
Ive put a whole bunch of images into MySql, and am referencing them through PHP. The code is as follows... PHP Code:
Filling MySQL Table From Within PHP
I don't seem to get the following right. In the following I try to fill a MySQL table named 'mutation'. The first element is a date but MySQL sees this as 0000-00-00 instead of the date 2002-11-01. Other problem is the textstring in $_POST['verklaring1'], in MySQL this stays empty. <?php $query = "insert into mutation values (2002-11-01, 1, 4, 1, 4, 10, 330 , ' $_POST['verklaring1'] ',N,N,N,N)"; mysql_db_query("projects", $query); ?>
Filling In For Deleted Images
I am creating an image gallary where the images are numbered 1, 2, 3 etc. Users will be uploading the images so if i need to delete an image, I need the code to be able to check if that number has been deleted and replace it with the next uploaded image. I have the code pulling from a txt file with a counter to name each file. The problem is that if images "36", "29" and "2" are removed... I need those slots to replaced in numerical order with the next uploaded images. So the next image will be named image "2" and will show up as the 2nd image on the page. Code:
Dynamically Filling Selection Boxes
I was wondering if anyone knows how to fill a selection box with different values depending on a selection made in a nother selection box in the same page. I dont know if what I'm tryin to do can be done or not, at least in PHP. First a quick background: We have a number of projects running right now, each of which is subdevided into various tasks. Now, I've got two selection boxes. The first contains a list of all current projects. What I want to do is this: when someon selects a project from the first box, I'd like the second box to be filled with a list of the tasks that have been assigned tot hat project.
Filling Form With Database Info
I have a table with 5 fields for a tour business activity list : (1) id -table key (2) name (3)description (4)picture -text link not binary(5) country. I would like to create a form that takes all the activitys an puts it neatly down on site in checkboxes so user can select activtys.this will be linked to form mail.i would like the activitys to be seperated by the country they r in?
How To Shortcut Execute Php Script Without Filling Out Form?
There is a website that has two input boxes inside a POST form that uses the action="rcon.php" here is the code for the form: <form method=POST action="/rcon.php"> <input size=25 type=text class="sm" name="addr"> <input size=20 type=text class="sm" name="rcon"> <input class="coolbuttonblue" type=submit value="Submit">...
PHP And $_POST
When we are passed info from a form, it is accessible in PHP using $_POST['var_name'], assuming that is the method used. What I am doing is taking those values and storing them in mysql. No special names, just entering the values as they come out of the array into the db one after the other. What I would like to do is load those values back into the form when someone revisits the page. I am curious if there is a simple way to load this array back into $_POST when a browser loads the page? Or does it need to be done piece by piece with javascript? Maybe this could be better handled with a cookie? Any thoughts or experiences would be greatly appreciated. Travis
Get Value Of $_POST[AAA[1]]
I am not able to get the value of $_POST[arrayelement[1]]. if the name of the variable is a variable it is ok, but I do not get if the name of the variable is in the form of an array element.
Using $_POST
What do I use instead of import_request_variables() to get the $_POST when my sever is using a version of php older than 4.1?
Use Of $_POST
In several post on this forum and other places I have noted the use of $_POST[something] (no quotes), $_POST['something'] (single quote), and $_POST["something"] (double quote). Which is correct, or does it matter?
Utf-8 In $_POST
does php have any built-in functions to convert post data from whatever format it arrives in to whatever format i wish? example: i use iso-8859-1 internally, and even specify accept-charset=iso-8859-1 in my html, but some browsers (phones) send utf-8 anyway. do i have to manually check if CONTENT_TYPE says "utf-8" and then...
$_POST
If I want to pass a value I read from a file using firstPhpFile.php to something like secondPhpFile.php, how do I store this value so I can use the $_POST variable to retrieve it later? I know how to retrieve values from my HTML code using $_POST by using the HTML element's name but how do I do this if the variable is a PHP variable holding a value I need to pass to a different PHP file?
Using $_POST In OOP
I am coding a CMS using OOP (Object Orientated Programming). I have just started, and I am half way through the user login/authentication area. How do I get data from a HTML form in a class? I have a regular HTML some like: <form action="post" method="checklogin.php"> <input type="text" name="username" /> <input type="text" name="password" /> </form> But thats all fine. Here is what I have done so far Code:
Php $_Post
i'm trying to figure out $_Post, while using it on an e-commerce site. Nothing too advance, just a system that works with gateway processor. I've created the form and setup connections to the gateway. As of right now, the gateway processor is pre made and cannot customize their fields. However, there are two fields which anything can be pass into, ($email_header and $email_footer) I'm sure someone knows how to do this. I basically want to call one of the input fields that is entered on the form and pass that info into the header variable. for example i tried using the birth field: Code:
For Every $_POST
Basically Ive Got Lots Of POSTs For A Multi-File Uploader It Needs To Run Through All The POST Variables eg file_1 file_2 file_3 etc.
$_POST ?
Okay I set up my variables like this: $FName= $_POST("FName"); the rest of the code is fine but...for some reason this code calls an undefined function error. Fatal error: Call to undefined function: array()
$_POST
I need my php pages to set some variables on a server level (in a virtual remote hosting) in order to have those variables seen from any other page of my website. I have 2 questions on the matter please: 1) I guess this can be done by using the $_POST array. is this the best way to set variables at server level? 2) if the use of $_POST is the proper way to set variables/array at server level, how do I assign a $_POST variable? is it compulsory to make a post form or the assignment can be done in an easier way, something like: $_POST[myvar] = 10;
Using $_POST As Source?
I am trying to create a query with the data passed through the form. The only reason I am making a query with it is because I need an array. On the form page, the user selected checkboxes (named SoupName). This info was passed to the next page, and I need to display each value of each checkbox in a table. Not a big deal... but I have always done this using a table in me database for the data, not a form. The query I am trying to use is below. Is this wrong? $query = mysql_query("SELECT SoupName FROM $_POST" ); Table creation:
PHP/Mysql $_POST
I am having a hard time trying to figure out how to have to $_POST variables on a php page. here is an example of my code. I am trying to have a user input both and Ip address and date which will get sent to a php page and used in the mysql query. How do I enter to variables in my mysql query. $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>"); mysql_select_db($dbname); //Query that is being run $query= "select inet_ntoa(ip_src), inet_ntoa(ip_dst), layer4_sport, layer4_dport, timestamp, sig_name from acid_event where inet_ntoa(ip_src)= '" . $_POST['IP'] . "'"; //this will try to spit out the previous sql query $result = mysql_query($query) or die('Query failed: ' . mysql_error()); //this is a line break before the spit output while ($line = mysql_fetch_row($result) ) { this is the code with just the "IP" _POST varible that is being enter on the HTML page. I have tried . $_POST['IP'] . "'", . $_POST['DATE'] . "'"; But it did not work. There is not much info online on mulitple POST commands. How would I have $_POST['IP'] and $_POST['DATE'] in my mysql query. thanks for all the help!
$_SESSION $_POST
I've got a basic user register form, action="POST". in my php code (on the same page, i store the $_POST stuff to a $_SESSION if the user screws a field up so they don't have to reenter all their info. But i'm thinking, why should i use $_POST at all if i can just us the $_SESSION array? or maybe even vice versa? or am i doing this all the wrong way?
$_POST And Https?
I have a script that displays and accepts form data. It has been working fine in my sandbox. When I move the script to the production area (same server, same version PHP, etc.) which is https, the form stops working. I put in a print_r($_POST); on both locations of the script. The one in the original location has values in the $_POST after form submission. The one in the https location has no values in the $_POST after form submission. I diff'd the files. They are identical.
_POST Vs. HTTP_POST_VARS
I'll admit, I'm still using $HTTP_POST_VARS. I know it's depreciated, but I do it anyways, it's how I learned PHP. Eventually I'll need to edit all my code (w/ search & replace)... but when? how urgent is this kind of thing? Does it really matter?
Problem With $_POST
I ran into a problem with the $_POST feature in my scripts. I just changed over to a new hosting company and now some of my scripts are acting wierd. I know it is probably a setting in the PHP.ini file, but I have no idea what to look for. The old server ran 4.2.2 and the new server runs 4.4.2 In my script I use $_GET to get the name of the text file that needs to be created and $_POST to get the content to post to the text file. I added error checking and the results (displayed using ECHO statements) of the script should return either "Success", "Unable to open file" or "Unable to save data". Using these results my program knows if the file was created. This all worked just fine until I started testing on the new server. Now the script returns the data that was sent during the post (writevar=my data to be posted) instead of any of the three possible results. The file is being successfully created, just that the script is now returning a statement that I have no idea where it is coming from.
Something Wrong With $_POST
I don't seem to be able to access the keys in an associative array. I have a script that dynamically generates a form. The form element names are generated based on image filenames, so I can't just access them the normal way in the form handler script. I tried looping through the $_POST array like this: foreach ($_POST as $key=>$value) { echo $key.'=>'.$value.'<br>' } and i get this output: 0=>Pay 1=>Pay 2=>on 3=>on 4=>tn__DSC2602.jpg 5=>tn__DSC2603.jpg Thos numbers are where I expected to see the form element names. Can anyond advise me on why this is happening?
Explanation Of $_post[]
I found the following code on this forum: action.php Code: <form method="post" action="foo.php"> How many sets? <input type="text" name="sets" /> <input type="submit" name="UpdateRates" value="Go To Foo.php"> </form> foo.php PHP Code:
|