0

我制作了一个非常简单的 PHP 网页来向以太网设备发送命令字符串。在我用字段集修改它之后,它不会再发布数据了。

这是工作网页:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<?php

// Checks to see if button pressed
if(isset($_POST['input'])) {

// Assigns value of button press to $input variable
$input=$_POST['input'];
//echo "$input<br />";

// Open the socket to the IP address
$sock = fsockopen('192.168.5.30:4660', NULL, $errno, $errstr);

// Send the value of the button press to the IP address
fwrite($sock, $input);

// Display the response from the socket on the webpage
echo fread($sock, 4096)."\n";

// Close the socket
fclose($sock); }

// If input is not set, then wait
else {
   // Input is not set, do something about it, raise an error, throw an exception, or whatever


}
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Audio Control</title>
</head>

<body>
<form method="post" action="">
<button name="input" value="CL1I1O1T" type="submit">Input 1</button>
<br />
<br />
<button name="input" value="CL1I2O1T" type="submit">Input 2</button>
<br />
<br />
<button name="input" value="CL1I3O1T" type="submit">Input 3</button>
<br />
<br />
<button name="input" value="CL1I4O1T" type="submit">Input 4</button>
<br />
<br />
<button name="input" value="CL1I5O1T" type="submit">Input 5</button>
<br />
<br />
<button name="input" value="CL1I6O1T" type="submit">Input 6</button>
<br />
<br />
<button name="input" value="CL1I7O1T" type="submit">Input 7</button>
<br />
<br />
<button name="input" value="CL1I8O1T" type="submit">Input 8</button>
<br />
<br />
<button name="input" value="DL1O1T" type="submit">Output 1 Off</button>
<br />
<br />

</form>
</body>
</html>

这是不工作的修改版本......有什么想法吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<?php

// Checks to see if button pressed
if(isset($_POST['input'])) {

// Assigns value of button press to $input variable
$input=$_POST['input'];
//echo "$input<br />";

// Open the socket to the IP address
$sock = fsockopen('192.168.5.30:4660', NULL, $errno, $errstr);

// Send the value of the button press to the IP address
fwrite($sock, $input);

// Display the response from the socket on the webpage
echo fread($sock, 4096)."\n";

   // Close the socket
fclose($sock); }

    // If input is not set, then wait
else {
   //input is not set, do something about it, raise an error, throw an exception, or whatever


}
?>


<head>
<style type="text/css">
<!--
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; 
padding: 0;
text-align: center;
color: #000000;
}

.newStyle1 {
float: left; 
}

.auto-style1 {
color: #FFFFFF;
font-size: 20px;
}

</style>
<title>Audio Control</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>

<form action="" method="post" >


<fieldset style="display:inline; border:none; padding:0px; margin:0px; vertical-align:top; class="newStyle1" style="height: 450px" >
  <legend align="center"; class="auto-style1">Backyard Audio</legend>
  <br/>
  <button name="input1" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I1O1T" type="submit">Computer</button>
  <br />
  <br />
  <button name="input2" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I2O1T" type="submit">Tuner</button>
  <br />
  <br />
  <button name="input3" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I3O1T" type="submit">Input 3</button>
  <br />
  <br />
  <button name="input4" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I4O1T" type="submit">Input 4</button>
  <br />
  <br />
  <button name="input5" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I5O1T" type="submit">Input 5</button>
  <br />
  <br />
  <button name="input6" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I6O1T" type="submit">Input 6</button>
  <br />
  <br />
  <button name="input7" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I7O1T" type="submit">Input 7</button>
  <br />
  <br />
  <button name="input8" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I8O1T" type="submit">Input 8</button>
  <br />
  <br />
  <button name="input9" style="height: 1.8em; width: 10em; font-size: 16px;" value="DL2O1T" type="submit">Backyard Audio Off</button>
  <br />
  <br />
</fieldset>


</form>
</body>
</html>
4

3 回答 3

1

you changed the name of the button (actually all buttons).

<button name="input"

<button name="input1" 
                   ^

input1 won't get posted to php as $_POST['input']. you have to change all button names back to input.

于 2013-08-03T14:11:42.017 回答
1

You have started a HTML comment before your CSS but does not closed it.

<style type="text/css">
<!-- 

Try removing it or completing it.

于 2013-08-03T14:13:26.623 回答
0

要检查表单是否已提交,您可以使用:

if (!empty($_POST))

要检查特定的提交按钮,您可以使用:

$_POST['input']
于 2013-08-03T14:32:55.123 回答