CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    PHP, convert value of variable into string.

    Hallo,

    I can not manage some task

    Code:
    $field_name = "surname";
    
    /* then I need to put this value to the $_POST array
    something like this */
    
    $var = $_POST[$field_name] ;
    
    /* I tried like this but  it doesn't work 
    $var = $_POST['\''.$field_name.'\'']);
    could anybody write me how I can manage when the 'field_name' value is changed dynamicly

    Thanks in advance

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP, convert value of variable into string.

    $_GET and $_POST are read only set by the data returned in a form or through AJAX.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Re: PHP, convert value of variable into string.

    so it means that there is no way to do it,
    Am I right ?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP, convert value of variable into string.

    Not what you are describing. What exactly are you wanting to do?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Re: PHP, convert value of variable into string.

    I hve solved it but in a other way, it means that I put in my Form the field with the fixed name. But I still thin if it is possible

    what I wanted to do:
    my php code creates a FORM where the field_name depends on some condition let say that on Monday the filed name must be 'Mo' and on the Tusday the filed name must be 'Tu' and so on ..., it is just a stupid example but I I theoreticaly wonder how it could be implemented in php code.

    If you could suggest me some way it would be nice.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP, convert value of variable into string.

    I'm sorry, but you're still not explaining yourself clearly. Why does it have to come from the form content?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: PHP, convert value of variable into string.

    Quote Originally Posted by Andrzej
    what I wanted to do:
    my php code creates a FORM where the field_name depends on some condition let say that on Monday the filed name must be 'Mo' and on the Tusday the filed name must be 'Tu' and so on ..., it is just a stupid example but I I theoreticaly wonder how it could be implemented in php code.

    If you could suggest me some way it would be nice.
    In that case you would access $_POST[$field_name], as per your first post. The value of $field_name would be exactly the same as that used to create the form.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  8. #8
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Re: PHP, convert value of variable into string.

    sorry, maybe my english is not good enough

    for instance:
    PHP Code:
    $field_name GetFieldName();


    $HTML .= '<form method="post" name=".myform" action="'.$this->ScriptFileName.'">';

    //...

    $HTM> .= "<input type=text name=" $field_name " value=" $val "</td>"


    // then I need to get value typed by a user
    $test $_POST=['$filed_name'];  // <= ofcourse it is wrong, but how it should be ... 

  9. #9
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP, convert value of variable into string.

    Get rid of the single quotes from the $_POST variable.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  10. #10
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Re: PHP, convert value of variable into string.

    Thank you
    it works, thank you that you was patient with me.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured