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
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to _POST a variable?

    I have a form which posts things like the users name and stuff. But how do I post my own stuff over to the next page without having to create a textfield/etc?

    Something like: $_POST['myVariable'] = 'This is what I want to send to the next page'
    Which of course will be invisible to the user, but when they click submit, not only will the users name etc get posted, but I can also receive the 'myVariable'?

    ?

  • #2
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    You'll have to use an input field no matter what. You'll just make the input field invisible to the user.

    Code:
    <input type="hidden" name="input" value="info you want to submit">
    Then you'll use $_GET $_POST or whatever to get the info.


    This question is borderline PHP. So you might want to ask to have it moved if you plan to discuss PHP related aspects.

    Of course if the info you are wanting to submit is always going to be the same, a timestamp, or some kind of php function, etc you could set up a variable in your PHP page.

    PHP Code:
    $myinfo "blah"

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The predefined $_POST variable is used to collect values from a form sent with method="post".

    Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

    Note: However, there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).

    thanks
    Last edited by VIPStephan; 09-28-2012 at 12:40 PM. Reason: removed spam link

  • #4
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    It depends on what John is trying to send. If the information is something that has to do with the user filling out the form then he'll want to use a hidden input field. However, if whatever information John is collecting doesn't have to come from the form it should be stored as a variable in his PHP code.

    This being said. John, what kind of information are you trying to collect?
    Last edited by stevenmw; 09-28-2012 at 01:30 PM. Reason: removed spam link

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm just trying to send strings to tell the next page what to do.

    I've got another problem. I have a page whereby when I click a link it uses javascript to 'window.open'. How can I _POST to that window?
    Last edited by john6; 09-28-2012 at 12:13 PM.

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,700
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    Quote Originally Posted by stevenmw View Post
    I can't tell if you are trying to be funny, or making a point? Lol.
    This is just a spammer (recognizable by the completely unrelated spam link at the end of the post – which I’ve removed) and you shouldn’t copy their spam links by quoting their entire posts. However, since the info in the post sounds fairly accurate to me (as non-back-end developer) I’m gonna leave it there for now.

  • #7
    New Coder
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    80
    Thanks
    1
    Thanked 8 Times in 8 Posts
    There is also the $_SESSION variable that stores values in the users session until they close the browser. So it would stick between pages.

    You start a session by calling the session_start() function

    Then store stuff like $_SESSION['name'] = 'Johnson';

    now an any page that has session_start() in it you can access $_SESSION['name']

  • #8
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Truffle View Post
    There is also the $_SESSION variable that stores values in the users session until they close the browser. So it would stick between pages.

    You start a session by calling the session_start() function

    Then store stuff like $_SESSION['name'] = 'Johnson';

    now an any page that has session_start() in it you can access $_SESSION['name']
    That sounds like a nice idea, but how do I attach the $_SESSION code to the link that opens the window? Sorry I'm a newb..

  • #9
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    If you just want to post a variable to a DB you don't have to use a session.

    PHP Code:
    $first $_POST['firstname'];
    $last $_POST['lastname'];
    $var "you variable";

    $con mysql_connect("localhost","user","pass");
    if (!
    $con)
    {
    die(
    'Could not connect: ' mysql_error());
     }

    mysql_select_db("my_db"$con);

    mysql_query("INSERT INTO table (first, last, var)
    VALUES ('$first', '$last','$var')"
    );

    mysql_close($con); 
    Obviously this needs to be cleaned up, and needs a few improvements. But it shows you don't need a session for simply posting a variable.


  •  

    Posting Permissions

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