简体   繁体   English

Beaglebone Black Rev C Debian,从HTML运行PHP程序

[英]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. 我有一个JavaScript程序,该程序使用node.js来控制从IO.html页到beaglebone的GPIO。 I just start the javascript with "node myscript.js". 我只是用“ node myscript.js”启动javascript。

I want to add a PHP file that will store values from the IO.html to a mysql db. 我想添加一个PHP文件,该文件将从IO.html存储值到mysql数据库。 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. 我已经创建了PHP和SQL数据库,但不确定如何或在何处托管PHP文件,以便html页面可以访问它。

The myscript.js reads the IO.html and listens on port 9090. myscript.js读取IO.html并侦听端口9090。

Does the PHP file need to hosted with hiawatha or apache on a different port? PHP文件是否需要在其他端口上托管hiawatha或apache?

<?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: html片段:

<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. 是的,您需要安装php5,而不是将php文件添加到/ var / www,而不是可以通过端口8080访问php文件。 192.168.7.2:8080/test.php 192.168.7.2:8080/test.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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