SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing serialized value through form

    Hello,

    I am trying to grab a serialized value from an array through a form using a hidden field. It is cutting off at the first quotation mark in the serialized string once the page reloades. I have tried
    PHP Code:
    addslashes(); 
    but it still cuts off just before the quotes (") just adding the slashes.

    Any ideas how I can get the string to carry over without it cutting off?

    PHP Code:
    $a[1] = 1;
    $a[2]=  2;
    $a[3] = 3;
    $a[4]=  4;
    $a[5] = 5;
    $a[6]=  6;
    $a[7]=  7;

    echo 
    "<input name=\"answ\" type=\"hidden\" value=\"".serialize($a)."\">";
    $answ $_POST['answ'];
    echo 
    "done<br />";
    echo 
    "answ = $answ"
    should look like this when the form is submitted:

    a:7:{i:1;s:1:"1";i:2;s:1:"2";i:3;s:1:"3";i:4;s:1:"4";i:5;s:1:"5";i:6;s:1:"6";i:7;s:1:"7";}

    but this is what it is displaying as currently:

    a:7:{i:1;s:1:

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
     $a[1] = 1; 
    $a[2]=  2; 
    $a[3] = 3; 
    $a[4]=  4; 
    $a[5] = 5; 
    $a[6]=  6; 
    $a[7]=  7;  
    echo "<input name=\"answ\" type=\"hidden\" value='".serialize($a)."'>";
    $answ = $_POST['answ']; 
    echo"done<br />"; 
    echo"answ = $answ";

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gimbles View Post
    Code PHP:
     $a[1] = 1; 
    $a[2]=  2; 
    $a[3] = 3; 
    $a[4]=  4; 
    $a[5] = 5; 
    $a[6]=  6; 
    $a[7]=  7;  
    echo "<input name=\"answ\" type=\"hidden\" value='".serialize($a)."'>";
    $answ = $_POST['answ']; 
    echo"done<br />"; 
    echo"answ = $answ";
    okay okay, so its been a long day... Thanks for the help.

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UPDATE: It worked beautifully but now I cannot get it to unserialize.

    PHP Code:
    $a[1] = 1
    $a[2]=  2
    $a[3] = 3
    $a[4]=  4
    $a[5] = 5
    $a[6]=  6
    $a[7]=  7;  
    echo 
    "<input name=\"answ\" type=\"hidden\" value='".serialize($a)."'>";
    $answ $_POST['answ']; 
    echo
    "done<br />"
    echo
    "answ = $answ";
    echo 
    "answ = $answ<br />";
    echo 
    "unserialized = ".unserialize($answ)."<br />"
    Last line is showing on screen as unserialized= array

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it is unserializing just fine

    its giving you back an array

    print_r(unserialize($answ));


Bookmarks

Posting Permissions

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