[英]PHP: using an html Form to call up a PHP action
我试图创建一个“提交”输入类型按钮,单击该按钮将调用我在PHP中定义的开关案例操作。 当单击“提交”按钮时,我希望form操作本质上创建一个链接并显示在URL form操作中,以便PHP文件正确调用它。
但是,当我单击提交按钮时,URL无法正确显示所需的链接和操作。
PHP:
$getuserid_result = mysql_query($getuseridsql, $conn);
$userid_array = mysql_fetch_array($getuserid_result);
$userid = $userid_array['uid'];
// Above code works fine and retrieves the current user's ID
// PHP Form code is below
// Variables used for creating the id of the input since the submit button is displayed
// in an HTML table with multiple rows. These variables are working fine.
$time_cell_row = 1;
$time_cell_column = 1;
echo "<form action='enter_time.php?uid='" . $userid . "?action=timesubmit method='get'>";
echo "<td><input name=submit_time type=submit id=submit_time" . $time_cell_row . $time_cell_column . "></input></td>";
echo "</form></tr>";
// PHP Action code
/* This is currently commented out and will eventually be filled with code to handle
the 'timesubmit' action
if (isset($_GET['action'])) {
switch (strtolower($_GET['action'])) {
case 'timesubmit':
}
}
*/
现在的问题是,当我单击“提交”按钮时,URL显示为enter_time.php?submit_time=Submit" instead of "enter_time.php?uid=3?action=timesubmit
您可能要在timesubmit之后添加最后的撇号
echo "<form action='enter_time.php?uid=" . $userid . "?action=timesubmit' method='post'>";
就在我头顶上应该是:
echo "<form action='enter_time.php?uid=" . $userid . "?action=timesubmit' method='get'>";
“ uid =“之后的单引号放在错误的位置。 除非在“时间提交”之后。
您在uid之后有一个引号,该引号不应存在:
"<form action='enter_time.php?uid=" . $userid . "?action=timesubmit method='get'>";
如果您使用表单将GET变量提交到url中,则可以执行以下操作
<a id="submit_time<?= $time_cell_row . $time_cell_column ?>" href="enter_time.php?uid=<?= $userid ?>">Submit Time</a>
如果您喜欢使用表格,以这种方式编写对我来说更清晰
PHP
<?php
$getuserid_result = mysql_query($getuseridsql, $conn);
$userid_array = mysql_fetch_array($getuserid_result);
$userid = $userid_array['uid'];
// Above code works fine and retrieves the current user's ID
// PHP Form code is below
// Variables used for creating the id of the input since the submit button is displayed
// in an HTML table with multiple rows. These variables are working fine.
$time_cell_row = 1;
$time_cell_column = 1;
?>
<form action='enter_time.php' method='get'>
<input type="hidden" name="action" value="<?= $timesubmit ?>">
<input type="hidden" name="uid" value="<?= userid ?>">
<input name="submit_time" type="submit" id="submit_time<?= $time_cell_row . $time_cell_column ?>" />
</form>
<?php
// PHP Action code
/* This is currently commented out and will eventually be filled with code to handle
the 'timesubmit' action
if (isset($_GET['action'])) {
switch (strtolower($_GET['action'])) {
case 'timesubmit':
}
}
*/
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.