stmt不插入且不会更新数据
<?php
if(isset($_GET['name']) and isset($_GET['herosize']) and isset($_GET['herocolor']) and isset($_GET['platform']))
{
echo "OKAY:".$_GET['name'].",OKAY:".$_GET['herosize'].",OKAY:".$_GET['herocolor'];
$con = mysqli_connect("127.0.0.1","####","########","phpmyadmin");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$queryCreateUsersTable = "CREATE TABLE IF NOT EXISTS `DGMOD` (
`ID` int(11) unsigned NOT NULL auto_increment,
`USERNAME` varchar(255) NOT NULL default '',
`PLATFORM` varchar(255) NOT NULL default '',
`CONFIG` varchar(255) NOT NULL default '',
PRIMARY KEY (`ID`)
)";
mysqli_query($con,$queryCreateUsersTable);
$stmt = mysqli_prepare($con,"IF EXISTS (SELECT * FROM DGMOD WHERE USERNAME = ? AND PLATFORM = ?)
THEN
UPDATE DGMOD SET USERNAME = ?, PLATFORM = ?, CONFIG = ? WHERE USERNAME = ? AND PLATFORM = ?
ELSE
INSERT INTO DGMOD (ID,USERNAME, PLATFORM, CONFIG) VALUES('1',?,?,?)");
mysqli_stmt_bind_param($con,'ssssssssss',$name1,$platform1,$name2,$platform2,$config2,$name3,$platform3,$name4,$platform4,$config4);
$name1=$name2=$name3=$name4=$_GET['name'];
$config2=$config4=$_GET['herosize']."+".$_GET['herocolor'];
$platform1=$platform2=$platform3=$platform4=$_GET['platform'];
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($con);
}
else
{
die("NO");
}
?>
警告: -
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, object given in C:\Program Files\VertrigoServ\www\test.php on line 26
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in C:\Program Files\VertrigoServ\www\test.php on line 30
Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in C:\Program Files\VertrigoServ\www\test.php on line 31
答案 0 :(得分:0)
也许这里有一个错误:
mysqli_stmt_bind_param($con,...
这应该是:
mysqli_stmt_bind_param($stmt,...
答案 1 :(得分:0)
mysqli_stmt_bind_param
的第一个参数需要为mysqli_stmt
,您传入的是mysqli
类型,因此是第一个错误。
替换此行:
mysqli_stmt_bind_param($con,'ssssssssss',$name1,$platform1,$name2,$platform2,$config2,$name3,$platform3,$name4,$platform4,$config4);
with:
mysqli_stmt_bind_param($stmt,'ssssssssss',$name1,$platform1,$name2,$platform2,$config2,$name3,$platform3,$name4,$platform4,$config4);
这将解决所有三个警告。