Query About Empty POST Arrays
I started programming in PHP recently and have a query about empty $_POST arrays. I can see two scenarios when this could happen.
1. When some tries to directly load the page to which data is being posted (for example, opening www.foo.com/xyz.php directly when a form action is xyz.php) 2. When the user clicks the submit button without entering anything.
I am aware that Javascript validation can take care of the second case, but it's unreliable. What is the accepted way of handling the above situations on the server side? Do I just reload the calling page if the array is empty?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Empty Arrays Or No Files
I have written a script which depending on the variable uploads $num files. The value of $num is stored in a mysql column and each file is uploaded in an array $file[], then placed in a directory by the name $id_$i.jpg (for example). The problem arises when I want to display the files back in a table. The $num is read back through the mysql query and if the amount of files is less than $num then I have a partially filled table. The cells with no filename display the icon which references "no image" as there is no file in the upload directory to reference. What I would like to know is 1)if when the form is submitted and only half of the files are uploaded could I set the array so it realises that only half of $file[] has been filled, or that only 6 of 12 files have been uploaded. 2) Alternately, could I count the number of files in a directory on my server and store that value as an variable to set the number of columns in my table? What would be the code for this??? Thanks in advance.
Removing Empty Elements From Arrays
I have tried looking through the online documentation at php.net, but I just can't seem to find ay function that will strip an array of any empty elements! It is for a basic form mailer, where I use $HTTP_POST_VARS. I want to strip off any empty form fields (as only 2 or 3 out of the 30 fields are required).
Empty Variables And 4.21 (POST/GET)
With global variables set to on, I always had the following in my script to make sure variables had a default value: if (empty($var)) { $var = 1;} Now with 4.21, I changed it to: if (empty($_GET['var'])) { $var = 1;} The problem is sometimes I use GET and sometimes I use POST. With global variables on it didn't matter. Now it does. Is there a way to do this? When I try if (empty($_GET['var']) || empty($_POST['var'])), it doesn't work because one or the other will always be empty at any one time.
From POST To GET: $_FILES Empty
I'm passing the code from $_POST to $_GET. I've a page upload using $_FILES. when the page was in $_POST, it worked fine, but now, in $_GET, the $_FILES is empty.
Empty Query, Query Fail
i am doing a user authentication but my problem is that when i type in user name and password it is Code:
Cannot Read Information From Form Using POST Or GET ($_Post Is Empty)
I am having problems in my php code. I am relatively new to php but I know some basics. This is the problem: when i try to echo some information that is typed into form back to the screen i get absolutely nothing. It seems like $_POST['name'] is an empty string, along with $_POST and $_GET['name']. I looked around to see if someone else had the same problem and found that some people's code didn't work because of IE6. but i also tried mine on Netscape and i got the same problem. So why is $_POST empty after posting information. Even $_GET was empty. all of those returned empty echo $_POST; echo $_POST['name']; echo $_GET['name']; here is the code: the code was originially meant to send an email but i commented the if statement out to see why it wasn't working <html> <head><title>Feedback</title></head> <body> <?php // Handle POST method. //if ($_POST) //{ $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; // Compose simple text message: $message = "Message from $name ($email) Comments: $comments"; // Send message to bob@microsoft.com mail("email@email.com", "Feedback", $message);
Empty Query
How can I tell if a query is empty: I need to test this $get_buddys = mysql_query($query_get_buddys) or die ("Invalid query". mysql_error());
Empty Query Issue
I'm trying to select a faculty member from a drop down box on one page, then click submit and the corresponding faculty member's info will come up on the next page in text boxes to allow editing. However when I select the faculty member and click submit, I get the following error: Can't execute SELECT Faculty* FROM Faculty WHERE LastName=: Query was empty. I'm guessing my problem is how I'm calling the selected item on the first page, but I can't get it figured out. Code:
WARNING: Empty Query
im having the strangest behaviour regarding mysql+php,i have this script that decides what should be displayed in the screen: Code:
PHP Code For An Empty MySQL Query
I'm working on coding a system that will create a user row in a table, but first, I need the system to check initially to make sure if there is the need to do it (IE: if no row exists for said user). Right now I have it set up to pull out the following: $permissions = "SELECT forumid, memberid, setupstatus FROM user WHERE forumid = " .$_COOKIE['bbuserid']; $permquery = mysql_query($permissions); I want it to check the table to see if there is a row for someone with a specific forumid (I use vBulletin, but it only relates in this case for the cookie). IF it shows up that there is a row, I want it to set $memberstat = 2; so that I can use that variable for various other page functions. If it shows up empty, it will set it equal to 1. How can I achieve this?
MySQL Query Returning Empty Column
Here's my code: $query_get_machine = sprintf("SELECT machines.ID, machines.NotifyID, machines.Name, notify.ID, notify.`Data` FROM machines RIGHT JOIN notify ON machines.notifyID = notify.ID WHERE machines.ID = %s", GetSQLValueString($colname_get_machine, "int")); Can anyone tell why the notify.`Data` column might be returned empty? All others display as they should.
MySQL Result Is Empty, But The Query Is Correct
I have written a script that grabs info from a database, and outputs it to a form. I figured I'd tidy things up a bit, and use a function to handle the queries, where I had previously hardcoded almost the same query several times. Code:
POST Arrays - Each As SQL Statement
I have a rather long form (122 SETS of questions - don't worry, it is just me using it, lol) I have the questions set up as "Survey ID, Question ID, Answer, Impact, Comments", which I have set up so that each question is an array, like so: ques_1['survey_id'] ques_1['question_id'] ques_1['answer'] ques_1['impact'] ques_1['comments'] I want to dynamically create SQL statements for each of these arrays, looping through the POST array, creating & running each of these dynamically created SQL statements. Unfortunately, when I attempt to access each array, I can't get the values of each key. For instance, consider the following: foreach ( $HTTP_POST_VARS as $key => $value ) { // I know for a fact, $value will be an array print("<pre>"); var_dump ($value); print("</pre>"); } Results in: array(5) { ["'question_id'"]=> string(1) "1" ["'survey_id'"]=> string(1) "2" ["'answer'"]=> string(3) "N/A" ["'impact'"]=> string(1) "0" ["'comments'"]=> string(12) "sdfsdfsdfsdf" } So, now I know that $value has 5 keys: question_id survey_id answer impact comments So, why can't I access $value['question_id']; (or any of the other values of the other keys)?
FIle Uploads: Empty _POST And _FILES Arrays When File Too Large
Uploading of files.. AFAIU from the manual, if a file is larger than the size defined in the form or larger than upload_max_filesize in php.ini, that _FILES['file']['error'] should hold an INT error code. The file upload system is working fine if the file is smaller than the defined size, but if it's larger, then both the _POST and _FILES arrays are completely empty: array(0) { } I can obviously check to see if $_FILES is set and contains elements, but I was hoping for more specific error handling (reason as to why the upload failed). Has anyone else encountered this? Any info welcomed =)
Help Needed Using Arrays In Query
I am try to use an array in a MySQL query using the in function. This requires a "," between each array entry but not at the end of the array. I can get a "," in between but I am left with one at the end. How can I get rid of the last ","?
MySQL Query And Arrays
I have a 'links' category on Table A and I want to retrieve the links from the Table and display them in a list-like fashion when the page is called upon. How would I go about seperating the links from one another (there a space inbetween each link.. EXAMPLE: http://asdf.com http://asdasd.com http://asdfff.com), loading them into an array (or using the best possible method to acces them easily) and then displaying them in a list like fashion..?
Populating Arrays From MySQL Query
I have the following code: http://pastebin.com/746601 The field 'material' in 'is_material' contains multiple values for each record in 'is_details'. Because of this I have used 'is_material_lookup' as a reference lookup table containing the 'style_code' and 'material_code' which refer to their full details in the respective tables. Currently I have got the script outputting all the details and one material then in the next block of data, repeating the details with a different material. What I would like to achieve is having 1 block of data with a list of all materials in that, instead of the repeat, but sadly I can't know exactly how to do it.
Arrays, Query Results And Select Box
I want/need to pre-select a drop-down box with a value if it's present in both a lookup table and user account table. After wrestling with this for a few hours I give up. i know this can't be this complicated, but apparently i'm missing something, so if anyone can suggest a way to go about this i'd be a little more sane. The idea is to have the user value already selected then when they change the value i'll update their account.
Using Arrays With Mysql Query Results
im currently in the process of making a piece of code that will firstly take all the data from a table in mysql and then assign it to an array. This data will consist of several different rows of data each with different infomation for each field in the table. i want to be able to use an array in a loop so that depending on which number of the loop is on will change the infomation that is assigned to a certain array. Code:
Disable Passing Arrays In Query String?
Is there any way to stop PHP from turning a query string like this: ?var[] into an array when it is read by $_GET['var']? I have quite a few input validations that are easily screwed up by this strange (and apparently undocumented???) feature...
POST And GET_VARS For Same Query?
I would like this page to process queries from two different sources: the first source is a form page which posts its variables...the second source URL encodes dynamic output. I can get it so one or the other works, but not both! PHP Code:
Get The Raw Content Of A POST Query
For some obscure reasons, I would need to be able to get the raw content of a POST query. This means I can't use the $_POST variable. Example: Code: POST /url.php HTTP/1.1 [...]Content-Length: [number] POST data here I want to be able to retrieve "POST data here" from a PHP script. That's about it. ^^
Simple POST Query
I have a simple query but due to my lack of php knowledge, can't find the right function. Let's say I have a form with 3 input fields. [field1] => 'hello' [field2] => 'ok' [field3] => 'goodbye' When I submit the page, I would like to echo this result: [field1] [field2] [field3] In other words, I want to have control over the posted header to determine if I should input in database the variable or not. If I use $HTTP_POST_VARS it actually returns the variable inside the header... i actually need the header's name.
Post Query Ending Up In $_GET?
I'm not sure if I've overlooked a config option, but the following HTTP POST request gives an empty $_POST array and $_GET['fred']=42... HTTP POST /js/test/testRequest.php?fred=42 HTTP/1.1
Ftp_nlist Returns False For Empty Directory Instead Of Empty Array
In an application installed with PHP5 it looks like ftp_nlist() returns false if the directory is empty, instead of an empty array as it should according to the manual. On the original server with PHP4 it works as expected. Is this a bug, or an undocumented change in PHP5, or a setting that could be changed somewhere?
PHP Session Is Empty And Session File Is Empty
I am trying to save a SESSION variable which looks to succeed because right after I print it out to verify it. I do so as follows: session_start(); <snip> $_SESSION['security_code'] = $code; The problem is that I submit a form on the same page and I need to check if the $_SESSION['security_code'] == $_POST['security_code'] however this condition is always false because $_SESSION['security_code'] is empty. I also checked the security files that are created in the PHP 'save_path' directory and it appears to be creating an empty session file. Can anyone suggest anything here? Also prior to the condition, I also do a session_start() and that doesn't help either. I got this code from a open source area and on that web site, if I test it it works fine. On my localhost it does not work. I'm not sure if I'm missing some configuration or whether PHP 5.2.2 has problems with sessions.
Post And Redirect With Post Data
The solution we have though up is the following: 1. The user fills in data in a form and hits submit - This submits (POST) to another page (redirect.php) 2. redirect.php adds more POST data to POST and then submits all this POST data to another page (offsite [payment portal]) The reason why we have to do this is for someone who knows our to read html source code, could easily find the sucessful page which will then do the processing we need to do on our side. Which means freebeis.
Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried. This is what my array looks like: array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" } This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s). I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation). I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:
Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for. so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase. say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.
PHP Post, Then HTML Post?
Using PHP, I want to POST or GET some variables to a second php page. This, I already know how to do. However, on the second php page, I want to use a simple, standard HTML form using the standard form-submitting method such as: <form action="https://orderpage.ic3.com/hop/orderform.jsp" method="post"> whereupon both sets of variables --- the earlier variables that were POSTed or GETted to the second page, along with the standard form variables derived within the second page --- will be POSTed to the above URL. In the second page, might I actually translate the received variables into actual HTML code? For instance, if my first page POSTed the variable xyz to the second page, then might the following code on the second page receive that variable and then include it when the second page's "Submit" button is pressed? <? $xyz=$_POST['xyz']; ?> <INPUT TYPE="HIDDEN" NAME="xyz" value="<?=$_POST['xyz']?>" > Or how, otherwise, might this be done?
PHP Update Query Mysql: Query Succussful?
I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work... thank you for your reply. $today= date("Y-m-d"); $qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'"; $result_6 = mysql_query ("$qq"); if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY $qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(Ƈ',Ƈ',Ƈ',Ƈ',Ƈ','$today')"; $result_6_2 = mysql_query ("$qq_2"); if (!$result_6_2){ $err_msg_sql_6= mysql_error(); $err_loc_6="$PHP_SELF"." // Query6: update totals_r"; } }
Speeding Up Query/code (query Within Result Set)
I'm looking for ideas on how to speed up this script. Basically it finds all the zip codes in a zipcode table, then looks for all the records in another table with those zip codes. Right now it finds all the zips then within that WHILE, it looks for a record in another table with that zip: PHP Code:
Using Empty And &&
Im checking to see if all of these are empty I have to do something: if (empty($_POST['phhome'] && $_POST['phcell'] && $_POST['phwork'] && $_POST['email'])) { But this isnt working and putting empty() around each didnt either. What I'm I not seeing?
Help With Empty()
this is my php: $pro1=addslashes($_POST['pro1']); $pro2=addslashes($_POST['pro2']); $pro3=addslashes($_POST['pro3']); $pro4=addslashes($_POST['pro4']); $pro5=addslashes($_POST['pro5']); for ($i=1;$i==5;$i++){ if (!empty(${'pro'.$i})) $pros.=${'pro'.$i}.""; } echo nl2br($pros); $pros return nothing, although $pro1 and $pro2 contain certain value...
Using If Empty
I am trying to use the if empty statment to make sure that every input box has been filled, the code looks like this. Code: if(empty($inputbox)){ print "you did not fill in a box.";} This works fine but there is about 20 input boxes and there must be an easier way to insted of repeating this 20 times.
Empty If / Else ?
I have never done this, but I have an if/else statement, and if I don't want anything to happen in the if statement, should I leave it empty or is there something that I could add??? A simple example (my actual code is much longer): <?php if(empty($_POST['fname'])){ }else{ $name = $_POST['fname'] mysql_query("INSERT INTO name(`first`) VALUES ('$name')); }?>
Testing For Empty Set?
basically, i want to query my db and see if the user has input a valid #.... if it matches a record im my table 'plu_coupons' then i will execute the code that allows a user to proceed... if the number input by the user does not match any of my records, he/she will be redirected to the sign-in page...
How To Empty An Array?
I've got a nested array, which I populate while processing and formatting results from a query. When I print the contents of the array I want to clear it so that I can use it again in the next iteration of the loop without the stuff I've printed still in it. Is there a straight forward way to do this? I've tried re-declaring it but that doesn't empty it.
Empty Sessions
When sessions are created by my message board or any other script. The sessions I can see inside the /tmp folder but when I open em up with pico I see NOTHING! no session variables or anything!! I have been tryin to figure this out forever here is my php.ini configuration for sessions [Session] session.save_handler = files ; handler used to store/retrieve data session.save_path = /tmp ; argument passed to save_handler ; in the case of files, this is the ; path where data files are stored session.use_cookies = 1 ; whether to use cookies session.name = PHPSESSID ; name of the session ; is used as cookie name session.auto_start = 1 ; initialize session on request startup session.save_handler = files ; handler used to store/retrieve data session.save_path = /tmp ; argument passed to save_handler ; in the case of files, this is the ; path where data files are stored session.use_cookies = 1 ; whether to use cookies session.name = PHPSESSID ; name of the session ; is used as cookie name session.auto_start = 1 ; initialize session on request startup session.cookie_lifetime = 0 ; lifetime in seconds of cookie ; or if 0, until browser is restarted session.cookie_path = / ; the path the cookie is valid for session.cookie_domain = ; the domain the cookie is valid for session.serialize_handler = php ; handler used to serialize data ; php is the standard serializer of PHP session.gc_probability = 1 ; percentual probability that the ; 'garbage collection' process is started ; on every session initialization session.gc_maxlifetime = 1440 ; after this number of seconds, stored ; or if 0, until browser is restarted session.cookie_path = / ; the path the cookie is valid for session.cookie_domain = ; the domain the cookie is valid for session.serialize_handler = php ; handler used to serialize data ; php is the standard serializer of PHP session.gc_probability = 1 ; percentual probability that the ; 'garbage collection' process is started ; on every session initialization session.gc_maxlifetime = 1440 ; after this number of seconds, stored ; data will be seen as 'garbage' and ; cleaned up by the gc process session.referer_check = ; check HTTP Referer to invalidate ; externally stored URLs containing ids session.entropy_length = 0 ; how many bytes to read from the file session.entropy_file = ; specified here to create the session id ; session.entropy_length = 16 ; session.entropy_file = /dev/urandom session.cache_limiter = nocache ; set to {nocache,private,public} to ; determine HTTP caching aspects ; cleaned up by the gc process session.referer_check = ; check HTTP Referer to invalidate ; externally stored URLs containing ids session.entropy_length = 0 ; how many bytes to read from the file session.entropy_file = ; specified here to create the session id ; session.entropy_length = 16 ; session.entropy_file = /dev/urandom session.cache_limiter = nocache ; set to {nocache,private,public} to ; determine HTTP caching aspects session.cache_expire = 180 ; document expires after n minutes session.use_trans_sid = 1 ; use transient sid support if enabled ; by compiling with --enable-trans-sid PLEASE I NEED HELP!! my /tmp is chmoded to 777 and I have tried everything... I know it isnt my forums because they worked on another server I transfered from and also it affects more than just the forums... every scripts that uses sessions is affected...
Empty Array?
I have a query that selects some data from a table based on the current ID selected. If the query does not return any results, I want it to continue to another query that will insert a record into the table. Below is what I have...but it will not insert anything if the first query...
PHP_AUTH_USER Is Empty
I use basic authentication in Apache. I like to use the global variable $_SERVER['PHP_AUTH_USER']. Unfortunately this variable is empty/no availabe. Same with PHP_AUTH_PW. AUTH_TYPE is working and states "Basic".
PHP Variables Are Always Empty
I'm trying to write a PHP script which allows to enter an username and a password and to click two buttons. If I start my PHP scripts 'mytest.php' I see the two input fields and the two buttons. However if I enter something to the input fields and press a button the echo commands show nothing. ====== PHP script 'mytest.php' ----------------------- <?php session_start(); if (!isset($_SESSION['auth_ok'])) { $_SESSION['auth_ok'] = false; } echo "$user <br>"; echo "$pass <br>"; echo "$button1 <br>"; echo "$button2 <br>"; echo "$auth_ok <br>"; if (isset($button1)){ echo "Button 1 has been pressed<br>"; $auth_ok = true;
Php Shows Up Empty
I havea problem with a php page, everytime I call it it presents me with an empty page, with only <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows- 1252"></HEAD> <BODY></BODY></HTML> as if have only made an empty php-page, I cannot figure out what the problem is, can anyone help me. (I have made a test page with only <?php ?> run it and it gave me the exact same result)
Empty Variables In 4.2.1+
I have a site where I check to see if a variable isset to see which file I include on a page - the URL would be something like: http://www.domain.com/?s Then in the PHP file I check to see: PHP Code:
Htaccess Must Be Empty
I am moving some php scripts to a new host. While getting to know the server, I ran into a strange problem. If I add a .htaccess file, or more specifically: a .htaccess with content, to a folder, requesting (html and php) files from that folder results in internal server error messages. If I upload an empty .htaccess file, all is fine. Then phpinfo() tells me I am using Apache/1.3.27.
$_POST Of Empty Vs 0 Value
working on LINUX I found that both empty($_POST['foo']) where $foo = 0 or &foo = empty gives me TRUE. I.e. I can not distingush between 0 and empty value - I need it for the text box value. What is the solution?
|