sparkynerd
sparkynerd

Reputation: 73

PHP Web page POST not working after adding fieldsets

I made a very simple working PHP webpage to send a command string to an ethernet device. After I modified it with fieldsets, it wont POST the data anymore.

Here is the working web page:

<!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>

Here is the modified version that is not working... any ideas?

<!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>

Upvotes: 0

Views: 623

Answers (3)

Duleendra
Duleendra

Reputation: 497

To check whether form is submitted you can use:

if (!empty($_POST))

To check a specific submit button you can use:

$_POST['input']

Upvotes: 0

Sameer Mahant
Sameer Mahant

Reputation: 114

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

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

Try removing it or completing it.

Upvotes: 1

bansi
bansi

Reputation: 57042

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.

Upvotes: 1

Related Questions