-1

Is there anyway to carry a value in php forward to a second page?

I tried doing something similar to what someone answered in this post, but it is telling me that i is undefined. I believe this is because I'm trying to use the ?i= after the action and not a link. Also I would need to have i as a variable instead of constant number. Is this possible and how would I fix this?

echo '<form action="gallery.php?i=0" method="post">
<input type="submit" name="action" value="Previous">
<input type="submit" name="action" value="Next">'; 
dane
  • 1
  • possible duplicate of [PHP: “Notice: Undefined variable” and “Notice: Undefined index”](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Funk Forty Niner Jun 09 '16 at 22:11
  • The ***less*** the good people know, the ***more time*** it takes to provide you with a solution and comments will just continue to grow until we know exactly which animal(s) were dealing with here. You may also lose people's interest in the question, depending how long they want to stick around. I myself, have a 5 mins. grace period for "no relevant code" questions. I know it may sound righteous, but I have better things to do than wait as do others I'm sure. And that 5 mins has already elapsed. – Funk Forty Niner Jun 09 '16 at 22:16

2 Answers2

1

Use an hidden input and its value in the php that generate the form.

At least I think this is what you were asking.

<input type="hidden" name="i" value="/* here goes your variable*/"
  • I just tried that but it seems that it thinks that my variable is in html – dane Jun 09 '16 at 22:09
  • echo ''; The index is showing up as green in phpstorm instead of orange. – dane Jun 09 '16 at 22:09
  • @dane that's because in a single quited string variables aren't parsed like in a double quoted one. http://php.net/manual/en/language.types.string.php#language.types.string.parsing – Christopher Jun 09 '16 at 22:17
0

I would suggest using:

<input type="hidden" name="i" value="0" />

To forward values. However keep in mind that malicious users can manipulate this value, therefore you should always validate it as well as other fields.

Jozef Spisiak
  • 852
  • 5
  • 13