PHP and LED

Hello.
My objective is when i fill up the PHP form and click the button under the form, the LED (connection with arduino) will turn on and the information entered will be save in the phpmyadmin. The problem is LED is not function. I am using comPort to turn the LED on.

How to make the LED turn on?

<?php


// SPECIFY USB PORT TO USE
$usb_comPort = "COM3";

     switch($_POST)
	{
		case isset($_POST['submitOn']):
			exec("ECHO 1 > $usb_comPort"); // Turn On LED 1
			break;
		case isset($_POST['submitOff']):
			exec("ECHO 2 > $usb_comPort "); // Turn Off LED 1
			break;
		case isset($_POST['submitOn1']):
			exec("ECHO 3 > $usb_comPort"); // Turn On LED 2
			break;
		case isset($_POST['submitOff1']):
			exec("ECHO 4 > $usb_comPort"); // Turn Off LED 1
			break;
		case isset($_POST['submitOn2']):
			exec("ECHO 5 > $usb_comPort"); // Turn On LED 3
			break;
		case isset($_POST['submitOff2']):
			exec("ECHO 6 > $usb_comPort"); // Turn Off LED 1
			break;
		case isset($_POST['submitOn3']):
			exec("ECHO 7 > $usb_comPort"); // Turn On LED 4
			break;
		case isset($_POST['submitOff3']):
			exec("ECHO  8 > $usb_comPort"); // Turn Off LED 1
			break;
		case isset($_POST['allon']):
			exec("ECHO  1,3,5,7 > $usb_comPort"); // Turn ON ALL 4 LED Bulbs
			break;
		case isset($_POST['alloff']):
			exec("ECHO  2,4,6,8 > $usb_comPort"); // Turn OFF ALL 4 LED Bulbs
			break;

	}


?>	


</head>


<body>

<h1>Parking Layout</h1>

<form method="post" action="infodriver.php">
<label>First Name</label>
<input type="text" name="First_Name" />


<label>Last Name</label>
<input type="text" name="Last_Name" />


<label>Phone Number</label>
<input type="number_format" name="Phone_Number" />






<label>Date</label>
<input type="date" name="Date" />






<label>Time</label>
<input type="time" name="Time" />









	<form  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
	
		<input type='submit' name='submitOn' value='Turn LED 1 ON'>
		<input type='submit' name='submitOff' value='Turn LED 1 OFF'>
		


		<input type='submit'  name='submitOn1'  value='Turn LED 2 ON'>
		<input type='submit'  name='submitOff1' value='Turn LED 2 OFF'>
		


		<input type='submit'  name='submitOn2'  value='Turn LED 3 ON'>
		<input type='submit'  name='submitOff2'  value='Turn LED 3 OFF'>
		


		<input type='submit'  name='submitOn3'  value='Turn LED 4 ON'>
		<input type='submit'  name='submitOff3'  value='Turn LED 4 OFF'>


		


		<input type='submit' name='allon' value='Turn ALL LEDs On'>
		<input type='submit' name='alloff' value='Turn ALL LEDs Off'>

	</form>
	

</body>

</html>

The problem is LED is not function.

No, the problem is that you only posted the PC code. It is NOT what is controlling the pin that the LED might, or might not, be correctly connected to.

Sir. This is the Arduino code that use port 3 to connect with localhost.

// Assign each of our input pins to an integer variable
int LED_one = 13;
int LED_two = 12;
int LED_three = 11;
int LED_four = 10;

void setup() {
Serial.begin( 9600 );

pinMode( LED_one, OUTPUT );
pinMode( LED_two, OUTPUT );
pinMode( LED_three, OUTPUT );
pinMode( LED_four, OUTPUT );

} //END OF SETUP

void loop() {
//wait until the serial connection is open
while (Serial.available() == 0);

//read from the serial connection; the - '0' is to cast the values as the int and not the ASCII code
int COM_value = Serial.read() - '0';

//print to the console for testing
Serial.println(COM_value);

//LED #`1
if( COM_value == 1 )
{
digitalWrite( LED_one, HIGH ); // HIGH VOLTAGE - TURNED ON
}
if( COM_value == 2 )
{
digitalWrite( LED_one, LOW ); // LOW VOLTAGE - TURNED OFF
}

//LED #2
if( COM_value == 3 )
{
digitalWrite( LED_two, HIGH ); // HIGH VOLTAGE - TURNED ON
}
if( COM_value == 4 )
{
digitalWrite( LED_two, LOW ); // LOW VOLTAGE - TURNED OFF
}

//LED #3
if( COM_value == 5 )
{
digitalWrite( LED_three, HIGH ); // HIGH VOLTAGE - TURNED ON
}
if( COM_value == 6 )
{
digitalWrite( LED_three, LOW ); // LOW VOLTAGE - TURNED OFF
}

//LED #4
if( COM_value == 7 )
{
digitalWrite( LED_four, HIGH ); // HIGH VOLTAGE - TURNED ON
}
if( COM_value == 8 )
{
digitalWrite( LED_four, LOW ); // LOW VOLTAGE - TURNED OFF
}

} //END OF LOOP

//read from the serial connection; the - '0' is to cast the values as the int and not the ASCII code

Subtracting '0' does NOT perform a cast.

Did I miss the part where the PHP script opens the port, sets the baud rate, etc.?

I am not familiar with PHP, but no need to opens port or sets the baud rate for PHP (i thinks so la)

but no need to opens port or sets the baud rate for PHP (i thinks so

You would be in the minority, then (and wrong).

https://www.lassiemarlowe.com/tutorials/power-led-bulbs-arduino-php-part-2/

it looks something like this, but i add the form where user can enter details and save it in the phpmyadmin

It is important to close the serial monitor in order for the browser based controls to work so once that is done you should be passing the values from the browser, through the USB ports and seeing the results.

So, the dumbass is relying on you opening and closing the serial monitor application, to open the port.

i tried without the code below, and it success but when i add the code, the LED not on.

<h1>Parking Layout</h1>

<form method="post" action="infodriver.php">
<label>First Name</label>
<input type="text" name="First_Name" />


<label>Last Name</label>
<input type="text" name="Last_Name" />


<label>Phone Number</label>
<input type="number_format" name="Phone_Number" />






<label>Date</label>
<input type="date" name="Date" />






<label>Time</label>
<input type="time" name="Time" />

Removing stuff from the PHP script will not help, unless you remove all the ECHO statements, which would render the sketch useless.

Either learn how to make PHP open the serial port, or open and close the serial monitor.

On windows machines you really can't use PHP via the pc serial port to control the arduino. PHP causes the serial port to open and close when it sends data via the serial port, causing the arduino to immediately reset. The arduino auto reset can be defeated, but that is another discussion.

PHP causes the serial port to open and close when it sends data via the serial port, causing the arduino to immediately reset.

A PHP script can open the serial port, and leave it open, just like any other programming language. It really all depends on how the script is being executed.

It looks, though, like that code is running in a browser, and that PHP is being started and stopped every time there is an interaction with the browser.

Which is probably why the script doesn't open the serial port, since it would have to do it every time it ran, which would, as you say, keep resetting the Arduino.