2017-06-28 78 views
-3

我想我的Android应用程序连接到一个在线数据库,但SQL错误的过程中弹出错误的SQL语法在PHP脚本

失败您的SQL语法错误;检查 对应于您MariaDB的服务器版本,在1号线

此使用 附近“QRY”正确的语法本手册是PHP脚本

<?php 
$name = "localhost"; 
$username ="**********"; 
$password ="**********"; 
$servername ="*********"; 
$conn = mysqli_connect($name,$username,$password,$servername); 
$typee=$POST["typee"]; 
$heighte=$POST["heighte"]; 
$weighte=$POST["weighte"]; 
$ranke=$POST["ranke"]; 
    $typee = $conn->real_escape_string($typee); 
    $hieghte = $conn->real_escape_string($hieghte); 
    $weighte = $conn->real_escape_string($weighte); 
    $ranke = $conn->real_escape_string($ranke); 
$qry = "INSERT INTO Naruto(typee,heighte,weighte,ranke)VALUES('$typee','$heighte','$weighte','$ranke')"; 
if(mysqli_query($conn,qry)===TRUE) 
      echo "Success"; 
     else 
      echo "Failed ".$conn->error; 
$conn->close(); 
+0

不要混用mysqli_面向对象和mysqli_过程样式。 'mysqli_query($ conn,qry)'应该是'$ conn-> query($ qry)'。改变它然后回报。编辑:哈,还有,你在'qry'之前缺少'$' – Terminus

+0

谢谢。有效!! –

回答

0

尝试传递$康恩到mysqli_query

例如,

if(mysqli_query($conn,qry)===TRUE) 
    echo "Success"; 
else 
    echo "Failed ".$conn->error; 

此外,您没有验证输入或转义,这意味着如果任何值有'字符它会打破你的查询和语法将不再有效。

$typee=$mysqli->real_escape_string($POST["typee"]); 
$heighte=$mysqli->real_escape_string($POST["heighte"]); 
$weighte=$mysqli->real_escape_string($POST["weighte"]); 
$ranke=$mysqli->real_escape_string($POST["ranke"]); 

此外,黑客可以执行所谓的SQL注入特制字符串传递到你的数据库妥协,或运行它的系统的攻击。

更多的显示方式:http://php.net/manual/en/mysqli.real-escape-string.php

在你的具体的例子,还检查间距是不是一个问题。

$qry = "INSERT INTO Naruto(typee,heighte,weighte,ranke) VALUES('$typee','$heighte','$weighte','$ranke')"; 

而且,在你更新后,你有拼写错误的变量所以$ heighte仍然没有被转义:

$heighte=$POST["heighte"]; 
... 
$hieghte = $conn->real_escape_string($hieghte); 
+0

对不起兄弟没有工作。感谢您的建议!我已经编辑了相应的问题。 –

+0

请参阅其他编辑,您有拼写错误的变量。 –

0

都都在VARCHAR类型的数据库的字段?在 '中包含每种类型可能会导致问题,例如,heighte,是一个整数。请检查一次。

+0

是的。我检查过他们。 –