我创建此代码以在我的数据库中添加一些数据而不重复。
但这不起作用,我无法将这个 php 创建的数据添加到我的表中。
有什么问题 ?
PS:我没有错误!
PPS:我在 wamp 服务器上执行此操作。
<?php
$con=mysqli_connect("localhost","root","","kosar");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
for ($i=0;$i<10;$i++) {
$n1 = rand(100000,999999);
$n2 = rand(100000,999999);
$pincode = (string)$n1;
echo $pincode;
echo nl2br("$pincode\n");
mysql_query ("INSERT IGNORE INTO kosar(ID, Code, Type, Used) VALUES('', '".$pincode."','1', '0')");
if(mysql_affected_rows() == 0)
{
// Duplicates found
}else{
// No duplicates were found
}
}
for ($i=0;$i<10;$i++) {
$n1 = rand(100000,999999);
$n2 = rand(100000,999999);
$pincode = (string)$n1;
echo $pincode;
echo nl2br("$pincode\n");
mysql_query("INSERT IGNORE INTO kosar(ID, Code, Type, Used) VALUES('', '".$pincode."','2', '0')");
if(mysql_affected_rows() == 0)
{
// Duplicates found
}else{
// No duplicates were found
}
}
for ($i=0;$i<10;$i++) {
$n1 = rand(100000,999999);
$n2 = rand(100000,999999);
$pincode = (string)$n1;
echo $pincode;
echo nl2br("$pincode\n");
mysql_query("INSERT IGNORE INTO kosar(ID, Code, Type, Used) VALUES('', '".$pincode."','3', '0')");
if(mysql_affected_rows() == 0)
{
// Duplicates found
}else{
// No duplicates were found
}
}
mysqli_close($con);
?>