简体   繁体   中英

Beaglebone Black Rev C Debian, Run PHP program from html

I have a javascript program that uses node.js to control GPIO from an IO.html page to the beaglebone. I just start the javascript with "node myscript.js".

I want to add a PHP file that will store values from the IO.html to a mysql db. I have the PHP and the SQL database created but I am not sure how or where to host the PHP file so that the html page can access it.

The myscript.js reads the IO.html and listens on port 9090.

Does the PHP file need to hosted with hiawatha or apache on a different port?

<?php
$con=mysqli_connect("localhost","root","PW","parameters");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// escape variables for security
$A0 = mysqli_real_escape_string($con, $_POST['A0']);
$A1 = mysqli_real_escape_string($con, $_POST['A1']);
$A2 = mysqli_real_escape_string($con, $_POST['A2']);
$A3 = mysqli_real_escape_string($con, $_POST['A3']);
$A4 = mysqli_real_escape_string($con, $_POST['A4']);

$sql="INSERT INTO inputs (A0, A1, A2, A3, A4)
VALUES ('$A0', '$A1', '$A2', '$A3', '$A4')";

if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
?> 

The html snippet:

<form action="test.php" method="post">
A0: <input type="text" name="A0">
A1: <input type="text" name="A1">
A2: <input type="text" name="A2">
A3: <input type="text" name="A3">
A4: <input type="text" name="A4">
<input type="submit">
</form>

Yes you need to install php5 Than you need to add the php file to /var/www than you can access the php file on port 8080 eg. 192.168.7.2:8080/test.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM