我想在我的服务器中将数据发送到我的arduino。 我在我的php页面上工作,但我的陈述有问题。
// Connect to MySQL
include('dbconnect.php');
$_ADPS = null;
$_ADCO = $_GET['ADCO'];
$_OPTARIF = $_GET['OPTARIF'];
$_ISOUSC = $_GET['ISOUSC'];
$_BASE = $_GET['BASE'];
$_HCHC = $_GET['HCHC'];
$_HCHP = $_GET['HCHP'];
$_EJPHN = $_GET['EJPHN'];
$_EJPHPM = $_GET['EJPHPM'];
$_BBRHCJB = $_GET['BBRHCJB'];
$_BBRHPJB = $_GET['BBRHPJB'];
$_BBRHCJW = $_GET['BBRHCJW'];
$_BBRHPJW = $_GET['BBRHPJW'];
$_BBRHCJR = $_GET['BBRHCJR'];
$_BBRHPJR = $_GET['BBRHPJR'];
$_PEJP = $_GET['PEJP'];
$_PTEC = $_GET['PTEC'];
$_DEMAIN = $_GET['DEMAIN'];
$_IINST = $_GET['IINST'];
$_ADPS = null;
$_IINST1 = $_GET['IINST1'];
$_IINST2 = $_GET['IINST2'];
$_IINST3 = $_GET['IINST3'];
$_IMAX = $_GET['IMAX'];
$_IMAX1 = $_GET['IMAX1'];
$_IMAX2 = $_GET['IMAX2'];
$_IMAX3 = $_GET['IMAX3'];
$_PMAX = $_GET['PMAX'];
$_PAPP = $_GET['PAPP'];
$_HHPHC = $_GET['HHPHC'];
$_MOTDETAT = $_GET['MOTDETAT'];
$_PPOT = $_GET['PPOT'];
// Prepare the SQL statement
//$_SQL = 'INSERT INTO `tbTeleinfo` (`DATE`, `ADCO`, `OPTARIF`, `ISOUSC`, `BASE`, `HCHC`, `HCHP`, `EJPHN`, `EJPHPM`, `BBRHCJB`, `BBRHPJB`, `BBRHCJW`, `BBRHPJW`, `BBRHCJR`, `BBRHPJR`, `PEJP`, `PTEC`, `DEMAIN`, `IINST`, `ADPS`, `IMAX`, `IINST1`, `IINST2`, `IINST3`, `IMAX1`, `IMAX2`, `IMAX3`, `PMAX`, `PAPP`, `HHPHC`, `MOTDETAT`, `PPOT`) VALUES(`' + $NOW() + '`, `'+ $_ADCO + '`, `' + $_OPTARIF + '`, `' + $_ISOUSC + '`, `' + $_BASE + '`, `' + $_HCHC + '`, `' + $_HCHP + '`, `' + $_EJPHN + '`, `' + $_EJPHPM + '`, `' + $_BBRHCJB + '`, `' + $_BBRHPJB + '`, `' + $_BBRHCJW + '`, ` ' + $_BBRHPJW + '`, `'+ $_BBRHCJR +'`, `' + $_BBRHPJR + '`, `' + $_PEJP + '`, `' + $_PTEC + '`, `' + $_DEMAIN + '`, `' + $_IINST + '`, `' + $_ADPS + '`, `' + $_IMAX + '`, `' + $_IINST1 + '`, `' + $_IINST2 + '`, `' + $_IINST3 + '`, `' + $_IMAX1 + '`, `' + $_IMAX2 + '`, `'+ $_IMAX3 + '`, `' + $_PMAX + '`, `' + $_PAPP + '`, `' + $_HHPHC + '`, `' + $_MOTDETAT + '`, `' + $_PPOT + '`)';
$SQL = "INSERT INTO tbTeleinfo (DATE, ADCO, OPTARIF, ISOUSC, BASE, HCHC, HCHP) VALUES( NOW() , '" + $_ADCO + "', '" + $_OPTARIF + "', '" + $_ISOUSC + "', '" + $_BASE + "', '" + $_HCHC + "', '" + $_HCHP + "')";
// Execute SQL statement
mysql_query($SQL);
在我试图在html页面中显示我的陈述之后:
echo $ SQL;
但是,结果是0,我的数据库总是空的。
我的数据网址是: http://martin-valentin.fr/teleinfo/add_data.php $ _ ADCO = 040422168851&安培; $ _ OPTARIF = BASE&安培; $ _ ISOUSC = 30&安培; $ _ HCHC = 0&安培; $ _ HCHP = 0
你看到我的错误了吗?
由于 V. MARTIN
答案 0 :(得分:0)
<强> dbconnect.php 强>
$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$db_selected = mysql_select_db('db_name', $conn);
if(!$db_selected){
die("Failed to select db");
}
echo "Seccessfully selected db";
你是PHP的。在PHP中,点操作符用于连接
<强> yourscript.php 强>
require_once "dbconnect.php";
$_ADPS = null;
$_ADCO = $_GET['ADCO'];
$_OPTARIF = $_GET['OPTARIF'];
$_ISOUSC = $_GET['ISOUSC'];
$_BASE = $_GET['BASE'];
$_HCHC = $_GET['HCHC'];
$_HCHP = $_GET['HCHP'];
$_EJPHN = $_GET['EJPHN'];
$_EJPHPM = $_GET['EJPHPM'];
$_BBRHCJB = $_GET['BBRHCJB'];
$_BBRHPJB = $_GET['BBRHPJB'];
$_BBRHCJW = $_GET['BBRHCJW'];
$_BBRHPJW = $_GET['BBRHPJW'];
$_BBRHCJR = $_GET['BBRHCJR'];
$_BBRHPJR = $_GET['BBRHPJR'];
$_PEJP = $_GET['PEJP'];
$_PTEC = $_GET['PTEC'];
$_DEMAIN = $_GET['DEMAIN'];
$_IINST = $_GET['IINST'];
$_ADPS = null;
$_IINST1 = $_GET['IINST1'];
$_IINST2 = $_GET['IINST2'];
$_IINST3 = $_GET['IINST3'];
$_IMAX = $_GET['IMAX'];
$_IMAX1 = $_GET['IMAX1'];
$_IMAX2 = $_GET['IMAX2'];
$_IMAX3 = $_GET['IMAX3'];
$_PMAX = $_GET['PMAX'];
$_PAPP = $_GET['PAPP'];
$_HHPHC = $_GET['HHPHC'];
$_MOTDETAT = $_GET['MOTDETAT'];
$_PPOT = $_GET['PPOT'];
$SQL = "INSERT INTO tbTeleinfo (DATE, ADCO, OPTARIF, ISOUSC, BASE, HCHC, HCHP) VALUES( NOW() , '" . $_ADCO . "', '" . $_OPTARIF . "', '" . $_ISOUSC . "', '" . $_BASE . "', '" . $_HCHC . "', '" . $_HCHP . "')";
$result = mysql_query($SQL);
if($result){
echo "Inserted data";
} else {
echo "Failed to insert".mysql_error();
}
答案 1 :(得分:0)
我建议使用mysqli而不是mysql_query,因为将来mysql _ *()将被删除。有关详细信息:MySQL vs MySQLi when using PHP
答案 2 :(得分:0)
在PHP中,您与.
而不是+
连接。您的查询应如下所示:
INSERT INTO tbTeleinfo (DATE, ADCO, OPTARIF, ISOUSC, BASE, HCHC, HCHP) VALUES( NOW() , '" . $_ADCO . "', '" . $_OPTARIF . "', '" . $_ISOUSC . "', '" . $_BASE . "', '" . $_HCHC . "', '" . $_HCHP . "')"