View Full Version : find out if POST array has value

12-09-2010, 07:28 AM
Hi, been working on this all day and im so close, im totally rewriting my user edit account php file and i got all the switches working ok accept for this one, i been at this one thing for 4 hours now and i cant seem to get it to catch the if statement correctly..

to start i am catching the POSTED value in an array like this..

$tmp = array_map("mysql_real_escape_string",$_POST);

then i do alot of checks for pw length and error checking and do some addslashes stuff..

then down on the bottom all i need to do is check to see if the user actually posted any new data in the fields something like this

if ($tmp)
update db with new post values
display message "account modified successfully"
display "No Changes Made To Account"

the problem im having is that its falling thru the if tmp switch, how do i check to see if $tmp array as new $_POST value i have tried numerious ifs using some array functions as well as isset and i just cant get it to see if $_POST data is there or not.. i should not have to check each field in array i should be able to just check if POST is set right.. ??? and that should cover the whole array correct. alittle lost here

thanks in advance..

12-09-2010, 12:03 PM
Enclose the entire code inside an if condition like



12-09-2010, 12:07 PM
I'm not sure if I totally understood, but is this the kind of thing?

if(isset($_POST) && is_array($_POST))

12-09-2010, 12:24 PM
not like that no because you probably have some POSTed control fields (submit etc) you have to check all of the possible fields... e.g.

foreach($editable as $k){
//got one

chances are you can do this elsewhere in your existing code but you get the idea ?

you could also at mysql_affected_rows() (http://php.net/manual/en/function.mysql-affected-rows.php), that will tell you if anything actually changed in the database in the last query.

12-09-2010, 04:33 PM
@ abduraooft thanks appreciate that but i was trying to get away from having write a half page of code to check each entity in the array...

@ Stooshie thank you also did try both of those although not together...

@firepages i didnt think i had to do a loop to do this but i think thats exactly what i need, looks great i will also check out mysql_affected_rows() also.. thank you all for your help i knew i was prob not reaching deep enough in my if but i just didnt know how...

thanks to all of you... :thumbsup:

12-09-2010, 05:08 PM
I am working on a simular code with costcodes;
****The big question of the day! How do we get the array values in a in a serverside query???

Here is my example which I believe your looking for the same?

Here is the serverside array im looking for

$sql = mysql_query("SELECT * FROM costcodes");
while($row = mysql_fetch_array($sql)){
$costcode = array(

Then use the array values wherever (in my case I just want to populate a dropdown
which the solution would work in your case )

Sorry about the curveball - I will post if I find the answer and we will kill two birds with one stone

<select name="CostCode" size="1">
foreach($costcode as $key=>$value){
printf('<option value="%s" %s>%s</option>',

12-09-2010, 05:13 PM
$costcode = array(

$costcode[$row['id']] = $row['CostCode'];

12-10-2010, 04:23 AM
well first i cant believe he hijacked my post lol, and second its not working at all...

now back to my issue of the post lol...

im thinking logically on this, there has to be way to take an array into a checksum or md5 or some value when it comes in, some hex value for the whole array...

lets say we call it $incomming_hexarray_value

now when we click the submit button it takes another value of the $_POST and compares them, if they are dif then that means the user has entered data somehow..

if that is the case then we update the database, if not then we dont and we display the message "no changes made"

the key to this whole thing is that when edit account pages comes up the var are displayed out of the array, so there has to be a simple to just grag a checksum value of that incomming array, without a half page of code to do it..

i dont need to know what they changed, i dont care about that, i just need to know if the bytes of data are dif from the time i load them on the page to when hit submit, simple switch, i just dont know the function i have tried md5 and checksum and they dont work on arrays..

update: ok i did find this


now i think all i need to do is fine out what the value is when it comes in, what changes when i changed data and set an if statement between the two.. i think lol

12-10-2010, 05:30 AM
ok i got it whoo hooo... here is the process in a nutshell

sha1 serialize the initial array

do your processing

write the data to the db

grab new member data array and sha1 serialize that

compare the two sha1 values, if they are the same sha1 value then display "no changes made to account"

if not then display " account updated successfully"

works perfect ... thanks everyone for all your help...

this took about 5 lines of additional coding is all