Jump to content


Photo

forms/variables/cookies+sessions help me please


  • Please log in to reply
13 replies to this topic

#1 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 24 August 2006 - 08:12 AM

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!

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 24 August 2006 - 08:49 AM

http://www.google.co...ms php tutorial

Lot's of good stuff there.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 August 2006 - 08:52 AM

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:

$somevar = $_POST['your_field_name_here'];

Now $somevar variable holds the value $_POST['your_field_name_here']; has.

#4 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 24 August 2006 - 04:09 PM

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.




#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 August 2006 - 04:17 PM

your error is with your quotes. try this:

$name = $_POST['name'];
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 24 August 2006 - 04:34 PM

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?

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 August 2006 - 04:42 PM

Post the code in form2.php, if its more than 10 lines post lines 3 - 8 here.

#8 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 24 August 2006 - 05:36 PM

I have it posted in form2.php

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 August 2006 - 06:15 PM

huh? I'm confused. I mean post the code. Did you post the code from form2.php earlier. Or have I missed something.

#10 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 August 2006 - 06:16 PM

repost form2.php
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#11 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 24 August 2006 - 06:49 PM

I don't understand.

#12 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 August 2006 - 08:30 PM

Post the code that is in form2.php here

#13 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 25 August 2006 - 12:01 AM

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!

#14 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 August 2006 - 01:19 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users