Jump to content

forms/variables/cookies+sessions help me please


jwk811

Recommended Posts

I'm trying to catch a piece of data from a form into a variable for further use. I'm not sure if this is even possible because I tried what I figured would be right and an error message came up on the next page.

Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/j/w/k/jwk811/html/form2.php on line 5

So this way I'm guessing that you can't make a piece data from a form into a variable that way. Well I don't know if I'm making a mistake but there is another way out there to do this without using variables.

This is what my situation looks like. I am trying to get data from a form to be used on ,not only the page it is directed to by the form action, but the next few pages after it.

I have asked about this to someone before and I think it has something to due with cookies or/and sessions, but I have no idea how to do this as I am very new to php and a lot of this stuff doesn't make that much sense to me. If anyone has any answers for me that will be incredible. Thanks for any help!
Link to comment
Share on other sites

Could you provide some code so can diagnose the error you are getting. You can get get form data into a another varibale like so:

[code=php:0]$somevar = $_POST['your_field_name_here'];[/code]

Now $somevar variable holds the value $_POST['your_field_name_here']; has.
Link to comment
Share on other sites

Okay, for my first page where the form is, I sent the data to another page where I tried to catch the data and put it into a variable like this.

Form-

<FORM METHOD="POST" ACTION="nextpage.php">
<INPUT TYPE="text" NAME="name" SIZE="30">
<INPUT TYPE="submit">

Next Page-

<?php
$name="$_POST["name"]";
echo $name;
?>

I just put out two test pages like that and coudn't get it to work. I keep getting this error:

Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/j/w/k/jwk811/html/form2.php on line 5

I'm gonna try playing around with this a little more but if you can tell me what I'm doing wrong that would be great. And as I said I'm using this data from the form to be caught into a variable so I can use that variable in further pages. Now, I'm not even sure that's going to work. So, if there is a different method to do that and anyone knows how I would really appreaciate some information.


Link to comment
Share on other sites

Ahhhh... I thought that would be the problem and changed it all then a different error came up:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/j/w/k/jwk811/html/form2.php on line 5

Would you know how to fix this one?
Link to comment
Share on other sites

I got the form data into variables. The variable can only be used on the same page. Why? If I lead the next form to another page and try to use the <?php echo $variable?> statment. It will not work and page won't come up because of that error. This is the warning that I got:

Warning: reset(): Passed variable is not an array or object in /home/content/j/w/k/jwk811/html/gdform.php on line 8

Warning: Variable passed to each() is not an array or object in /home/content/j/w/k/jwk811/html/gdform.php on line 13

Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/w/k/jwk811/html/gdform.php:8) in /home/content/j/w/k/jwk811/html/gdform.php on line 23

Does anyone know what this means? Please help!
Link to comment
Share on other sites

You can only use variables on one page, you cannot use variables one page and then be able to use the same variable on another page. As when php parses the script it stops at the end and clears any variables. However if you want to use a variable on one page and then use it in another you'll have to use a cookie or session.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.