PHP:使用html表单调用PHP操作

时间:2014-08-21 02:48:07

标签: php html forms

我正在努力创建一个'提交'单击时输入类型按钮将调用我在PHP中定义的switch case动作。当提交'单击按钮,我希望表单操作基本上创建一个链接并显示在URL表单操作中,以便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;

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':



    }
   } 
      */

现在的问题是,当我点击提交&#39;按钮,显示的网址为enter_time.php?submit_time=Submit" instead of "enter_time.php?uid=3?action=timesubmit

4 个答案:

答案 0 :(得分:1)

您可能希望在timesubmit

之后添加最终的撇号

echo "<form action='enter_time.php?uid=" . $userid . "?action=timesubmit' method='post'>";

答案 1 :(得分:1)

我的头脑应该是:

echo "<form action='enter_time.php?uid=" . $userid . "?action=timesubmit' method='get'>";

&#34; uid =&#34;之后的单引号是在错误的地方。不应该在&#34; timesubmit&#34;。

之后

答案 2 :(得分:1)

你在uid之后有一个不应该出现的引用:

"<form action='enter_time.php?uid=" . $userid . "?action=timesubmit method='get'>"; 

答案 3 :(得分:1)

如果您使用表单将GET变量提交到网址,则可以执行类似

的操作
<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':



        }
     } 
            */

?>