$ _POST并不总是设置? [英] $_POST not always set?

查看:59
本文介绍了$ _POST并不总是设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以点击一个按钮,而不是它的值和名称存储在_POST中的



我有这个脚本用一个按钮就可以了。当您单击按钮时,页面

会自行发布。第一次单击此保存更改按钮时,_POST

为空。单击按钮后,再次加载页面,如果您再次单击保存更改,则会正确设置_POST。什么是

那个?


$ studentCode; //将保留当前的学生代码(如果适用)


....

foreach(array_keys($ _ POST)as $ key)

{

$$ key = $ _POST [$ key];

print" $ key is $ {$ key}< br />" ;;

echo"它是:" 。 $ _POST [" Submit"]。 " br>";

}

if($ _POST [" Submit"] ==" Add Student")//保存按钮被点击

addRecord();

elseif($ _POST [" Submit"] ==" Save Changes")//保存更改按钮被点击

updateStudent();

echo"我们正在保存更改< br>";

elseif($ _GET [" action"]!= 添加)

getOldData($ record);


echo"< table summary = \" \" cellpadding = \" 5 \">" ;;


function printLabelCell()

{

echo " \ n< tr>< td align = \" right \">" ;;

}


if( isset($ _ GET [" studentCode"]))

$ studentCode = $ _GET [" studentCode"];

elseif(isset($ _ POST [" studentCode" ;]))

$ studentCode = $ _POST [" studentCode"];


if($ studentCode!="")

$ postType =" post?studentCode =" 。 $ studentCode;

else

$ postType =" post";


echo''< form action =" addEditStudent.php" method ="''。 $ postType。 ''">'';


// ...在单元格中打印控件...


echo"< ; tr>< td colspan = \" 2 \" align = \" center \">" ;;


echo''< br>'';


if($ _GET [" action"] ==" add"或isset($ _ POST [" firstName"]))

echo''< input type =" Submit"命名= [提交" value =" Add Student">& nbsp;

& nbsp; &安培; NBSP; '';

else

echo''< input type ="提交"命名= [提交" value ="保存更改">'';


echo''& nbsp; &安培; NBSP; &安培; NBSP; < input type ="重置"命名= QUOT;复位" value ="清楚

数据"< br>< br>'';


echo"< / td>< / tr>< / table>" ;;


echo"< / form>" ;;


函数DisplayTextbox($ vname,$ size,$ value)

{

echo"< / td>< td><输入类型= \" text \" ; name = \"" 。 $ vname。 " \"尺寸= \""

.. $尺寸。 " \"值= \"" 。 $ value。 " \">< / td>< / tr>" ;;

}


mysql_close($ link);

....


< Ade

-

Adrian Parker。被任命的牧师。 < ad *********** @ sympatico.ca>


将图形暴力视为娱乐的社会......不应该是
毫无意义的暴力事件打破了最年轻的梦想和b $ b bigh bigh...... - 少尉(2004年3月)

Is it possible to click on a button, and not have it''s value and name stored
in _POST?

I have this script with a button on it. When you click the button, the page
posts to itself. The first time you click this Save Changes button, _POST
is empty. After clicking the button, and the page is loaded again, if you
click Save Changes once more the _POST is properly set. What''s up with
that?

$studentCode; // Will hold the current student code, if applicable

....

foreach(array_keys($_POST) as $key)
{
$$key = $_POST[$key];
print "$key is ${$key}<br />";
echo "It is: " . $_POST["Submit"] . "<br>";
}
if ($_POST["Submit"] == "Add Student") // Save button was hit
addRecord();
elseif ($_POST["Submit"] == "Save Changes") // Save changes button was hit
updateStudent();
echo "We''re saving changes<br>";
elseif ($_GET["action"] != "add")
getOldData($record);

echo "<table summary=\"\" cellpadding=\"5\">";

function printLabelCell()
{
echo "\n<tr><td align=\"right\">";
}

if (isset($_GET["studentCode"]))
$studentCode = $_GET["studentCode"];
elseif (isset($_POST["studentCode"]))
$studentCode = $_POST["studentCode"];

if ($studentCode != "")
$postType = "post?studentCode=" . $studentCode;
else
$postType = "post";

echo ''<form action="addEditStudent.php" method="'' . $postType . ''">'';

// ... print controls in the cells ...

echo "<tr><td colspan=\"2\" align=\"center\">";

echo ''<br>'';

if ($_GET["action"] == "add" or isset($_POST["firstName"]))
echo ''<input type="Submit" name="Submit" value="Add Student">&nbsp;
&nbsp; &nbsp; '';
else
echo ''<input type="Submit" name="Submit" value="Save Changes">'';

echo ''&nbsp; &nbsp; &nbsp; <input type="Reset" name="Reset" value="Clear
Data"><br><br>'';

echo "</td></tr></table>";

echo "</form>";

function DisplayTextbox($vname, $size, $value)
{
echo "</td><td><Input type=\"text\" name = \"" . $vname . "\" Size = \""
.. $size . "\" value=\"" . $value . "\"></td></tr>";
}

mysql_close($link);
....

<Ade
--
Adrian Parker. Ordained priest. <ad***********@sympatico.ca>

"A society that views graphic violence as entertainment ...should not be
surprised when senseless violence shatters the dreams of it''s youngest and
brightest..." - Ensign (March 2004)

推荐答案

studentCode; //将保留当前的学生代码(如果适用)


....


foreach(array_keys(
studentCode; // Will hold the current student code, if applicable

....

foreach(array_keys(


_POST)as


key)

{
key)
{


这篇关于$ _POST并不总是设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆