Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP提交表单不工作_Php_Submit - Fatal编程技术网

PHP提交表单不工作

PHP提交表单不工作,php,submit,Php,Submit,下面是一段将查询结果输入单选按钮的代码。然后,当用户按下表单中的一个按钮时,它会移动到页面test.php。我遇到了一个问题,尽管第二个代码(在test.php上)似乎不起作用,但我看不出任何不起作用的原因。任何想法都很棒。谢谢 <?php while($row = mysql_fetch_assoc($result)): ?> <tr> <td><input type="radio" name="server" value="<?php

下面是一段将查询结果输入单选按钮的代码。然后,当用户按下表单中的一个按钮时,它会移动到页面test.php。我遇到了一个问题,尽管第二个代码(在test.php上)似乎不起作用,但我看不出任何不起作用的原因。任何想法都很棒。谢谢

<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
    <td><input type="radio" name="server" value="<?php echo $row['serverId']; ?>" /></td>
    <td><?php echo $row['userName']; ?></td>
    <td><?php echo $row['dateCreated']; ?></td>
    <td><?php echo $row['serverName']; ?></td>
    <td><?php echo $row['serverId']; ?></td>
    <td><?php echo $row['publicDNS'] ?></td>
    <td><?php echo $row['isRunning']; ?></td>
</tr>
<?php endwhile; ?>
</table>
<br>
<?php endif; ?>

<form method="post" name="server_information" id="server_information" action="test.php">
<input type="submit" name="server_stop" value="Stop Server"/>
<input type="submit" name="server_terminate" value="Terminate Server"/>
</form>

</body>
</html>  


第二个代码:

<?php
if (isset($_POST['server_stop'])) {
    echo "Server Stopped";
}

if (isset($_POST['server_terminate'])) {
    echo "Server Terminated"
}

?>

$\u POST['submit']
必须是
$\u POST['server\u stop']

<?php
if (isset($_POST['server_stop'])) {
    echo "Server Stopped";
}

if (isset($_POST['server_terminate'])) {
    echo "Server Terminated";
}

?>

您的代码:

<?php
if (isset($_POST['server_stop'])) {
    echo "Server Stopped";
}

if (isset($_POST['server_terminate'])) {
    echo "Server Terminated"
}

?>
现在在PHP端,您将检查
$\u POST['clicked']
,并查看按下了哪个按钮

if (isset($_POST['submit'])){
  $name =trim($_POST['name']);
  if (empty($name)){
    echo "please input name";    
  }
  else if (!preg_match("/^[a-zA-Z ]*$/",$name)){
    $namerr = "Only letters and white space allowed";
  }
}
编辑:
请注意这里正在使用Jquery。。。因此,请务必加载该库。

如果您根本不想使用javascript,并且您只需要在表单中使用这些提交按钮,您也可以这样做:

<form method="post" name="server_information" id="server_information" action="test.php">
<input type="submit" name="clicked" value="Stop Server"/>
</form>
<form method="post" name="server_information" id="server_information" action="test.php">
<input type="submit" name="clicked" value="Terminate Server"/>
</form>


现在只需检查
$\u POST['clicked']
,您就会看到按下了哪个按钮。

我更新了代码,但它仍然不显示echo语句中的内容。还有其他想法吗?我编辑了代码,再试一次。我将
echo“服务器终止”
更改为
echo“服务器终止”谢谢。真不敢相信我错过了那个半上校的比赛(!preg_match(“/^[a-zA-Z]*$/”,$name)){$namerr=“只允许字母和空格”;}
if (isset($_POST['submit'])){
  $name =trim($_POST['name']);
  if (empty($name)){
    echo "please input name";    
  }
  else if (!preg_match("/^[a-zA-Z ]*$/",$name)){
    $namerr = "Only letters and white space allowed";
  }
}
if (isset($_POST['submit'])){
  $name =trim($_POST['name']);
  if (empty($name)){
    echo "please input name";    
  }
  else if (!preg_match("/^[a-zA-Z ]*$/",$name)){
    $namerr = "Only letters and white space allowed";
  }
}