Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts

    find out if POST array has value

    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..

    Code:
      //sanitation
       $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

    Code:
      if ($tmp)
           {
            update db with new post values 
             display message "account modified successfully" 
           }else{
    	 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..

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Enclose the entire code inside an if condition like
    PHP Code:
    if(isset($_POST['name_of_any_field_in_form'])){


    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    durangod (12-09-2010)

  • #3
    Regular Coder Stooshie's Avatar
    Join Date
    Mar 2008
    Location
    Dundee, Scotland
    Posts
    378
    Thanks
    9
    Thanked 39 Times in 39 Posts
    I'm not sure if I totally understood, but is this the kind of thing?
    Code:
    if(isset($_POST) && is_array($_POST))
    {
    }
    Regards, Stooshie
    O

  • Users who have thanked Stooshie for this post:

    durangod (12-09-2010)

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,058
    Thanks
    10
    Thanked 96 Times in 94 Posts
    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.

    PHP Code:
    <?
    $has_edited
    =false;
    $editable=array('address','phone','etc...');
    foreach(
    $editable as $k){
      if(!empty(
    $_POST[$k])){
         
    //got one
         
    $has_edited=true;break;
    }}
    chances are you can do this elsewhere in your existing code but you get the idea ?

    you could also at mysql_affected_rows(), that will tell you if anything actually changed in the database in the last query.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    durangod (12-09-2010)

  • #5
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    @ 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...

  • #6
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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
    Code:
    <?php
    $sql = mysql_query("SELECT * FROM costcodes");
      while($row = mysql_fetch_array($sql)){
        $costcode = array(
    $row[id]=>$row[CostCode],
    ); 
    }
    ?>
    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

    Code:
    <select name="CostCode" size="1">
    <?php
    foreach($costcode as $key=>$value){
      printf('<option value="%s" %s>%s</option>',
        $key,($_POST['costCode']==$key?'selected="selected"':''),$value);
    }
    ?>
    </select>
    Last edited by DataTalk; 12-09-2010 at 04:13 PM.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Change
    PHP Code:
    $costcode = array(
    $row[id]=>$row[CostCode],
    ); 
    to
    PHP Code:
    $costcode[$row['id']] = $row['CostCode']; 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    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
    Code:
    md5(serialize($array));
    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
    Last edited by durangod; 12-10-2010 at 03:56 AM. Reason: update

  • #9
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •