MYSQL没有从PHP接收数据 [英] MYSQL not receiving data from PHP
本文介绍了MYSQL没有从PHP接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从输入发送数据到我的sqldata基地。这里是它试图发送信息到数据库的编码。它不会出现在数据库中;
I am trying to send data from input to a my sqldata base. Here is the coding for it trying to send the information to the database. It doesn't appear in the database; what is wrong with the coding?
<?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."')");
?>
推荐答案
您正在混合mysql和mysqli。更改:
You are mixing mysql and mysqli. Change:
mysql_query("INSERT INTO 'mensscore', (Name, Club, Level, App, Score);
VALUES ('".$a."',
'".$b."',
'".$c."',
'".$d."'
'".$g."')");
To:
mysqli_query($con, "INSERT INTO `mensscore` (Name, Club, Level, App, Score)
VALUES ('$a',
'$b',
'$c',
'$d',
'$g'
);");
另请参阅和 PHP:mysqli_stmt - 手动,因为使用POST并不总是安全的,因为人们可以做SQL注入。
Also see How can I prevent SQL injection in PHP and PHP: mysqli_stmt - Manual because using POST is not always safe as people can do SQL injection.
这篇关于MYSQL没有从PHP接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文