2016-06-09 57 views
-1

Is there anyway to carry a value in php forward to a second page?嘗試在HTML和PHP

我試圖做類似的什麼人在這個崗位回答的東西結轉的值,但它告訴我,我是不確定的。我相信這是因爲我試圖在行動之後使用 ?i =而不是鏈接。此外,我將需要我作爲一個變量,而不是常數。這是可能的,我將如何解決這個問題?

echo '<form action="gallery.php?i=0" method="post"> 
<input type="submit" name="action" value="Previous"> 
<input type="submit" name="action" value="Next">'; 
+0

[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-索引號) –

+0

***少***好人知道,***更多時間***爲您提供解決方案和意見將會持續增長,直到我們確切地知道哪些動物是在這裏處理。你也可能會失去人們對這個問題的興趣,這取決於他們想要堅持多久。我自己,有一個5分鐘。寬限期爲「無相關代碼」問題。我知道這聽起來可能是正確的,但我有更好的事情要做,而不是像其他人一樣等待。而這5分鐘已經過去了。 –

回答

1

在生成表單的php中使用隱藏輸入及其值。

至少我認爲這是你問的問題。

<input type="hidden" name="i" value="/* here goes your variable*/" 
+0

我只是試過,但它似乎認爲我的變量是在html – dane

+0

echo'';該指數在phpstorm中顯示爲綠色,而不是橙色。 – dane

+0

@dane這是因爲在一個單獨的字符串中,變量不像在雙引號中那樣被解析。 http://php.net/manual/en/language.types.string.php#language.types.string.parsing – Christopher

0

我會建議使用:

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

要轉發值。但請記住,惡意用戶可以操縱此值,因此您應該始終驗證它以及其他字段。