mysql接收php,MYSQL没有从PHP接收数据

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?

$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."')");

?>

解决方案

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'

);");

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值