我正在尝试将数据从输入发送到我的sqldata基础。以下是尝试将信息发送到数据库的编码。它没有出现在数据库中;编码出了什么问题?
<?php
$con=mysqli_connect(/*hostname*/"localhost",
/*username*/"user",
/*password*/"pass",
/*database name*/"dbase");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$a = mysqli_real_escape_string($con, $_POST['a']);
$b = mysqli_real_escape_string($con, $_POST['b']);
$c = mysqli_real_escape_string($con, $_POST['b']);
$d = mysqli_real_escape_string($con, $_POST['d']);
$e = mysqli_real_escape_string($con, $_POST['e']);
$f = mysqli_real_escape_string($con, $_POST['f']);
$g = 10 + ($e - $f);
mysql_query("INSERT INTO 'mensscore', (Name, Club, Level, App, Score);
VALUES ('".$a."',
'".$b."',
'".$c."',
'".$d."'
'".$g."')");
?>
答案 0 :(得分:1)
你正在混合mysql和mysqli。变化:
mysql_query("INSERT INTO 'mensscore', (Name, Club, Level, App, Score);
VALUES ('".$a."',
'".$b."',
'".$c."',
'".$d."'
'".$g."')");
要:
mysqli_query($con, "INSERT INTO `mensscore` (Name, Club, Level, App, Score)
VALUES ('$a',
'$b',
'$c',
'$d',
'$g'
);");
另请参阅How can I prevent SQL injection in PHP和PHP: mysqli_stmt - Manual,因为使用POST并不总是安全的,因为人们可以进行SQL注入。
答案 1 :(得分:0)
您在查询中有一些错误。首先使用mysqli_query()
,因为你在使用mysqli。删除不需要的,和;从查询中试试,
mysqli_query($con,"INSERT INTO 'mensscore' (Name, Club, Level, App, Score)
VALUES ('$a',
'$b',
'$c',
'$d'
'$g')");
答案 2 :(得分:0)
试试这个
mysqli_query($con,"INSERT INTO mensscore (Name, Club, Level, App, Score)VALUES ('".$a."', '".$b."', '".$c."', '".$d."', '".$g."')");
答案 3 :(得分:0)
试试这个
mysqli_query("INSERT INTO mensscore (Name, Club, Level, App, Score)
VALUES ('{$a}','{$b}','{$c}','{$d}','{$g}'");
答案 4 :(得分:0)
试试这个
<?php
$con=mysqli_connect("localhost","user","pass","dbase");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$a = mysqli_real_escape_string($con, $_POST['a']);
$b = mysqli_real_escape_string($con, $_POST['b']);
$c = mysqli_real_escape_string($con, $_POST['b']);
$d = mysqli_real_escape_string($con, $_POST['d']);
$e = mysqli_real_escape_string($con, $_POST['e']);
$f = mysqli_real_escape_string($con, $_POST['f']);
$g = 10 + ($e - $f);
$sql = "INSERT INTO mensscore(Name, Club, Level, App, Score)VALUES('".$a."','".$b."','".$c."','".$d."''".$g."')";
$result = $con->query($sql) or die("Error executing query" . mysqli_error($conn));
?>
答案 5 :(得分:0)
不要引用表名mensscore
在VALUES
关键字