For some reason my query isn't working, I'll post the code and output of $_POST.
由于某种原因我的查询不起作用,我将发布$ _POST的代码和输出。
I will also add a screenshot for the structure of the database.
我还将添加数据库结构的屏幕截图。
$_POST:
Code:
ini_set('display_errors',1);
error_reporting(E_ALL);
echo "<pre>";
var_dump($_POST);
echo "</pre>";
$mysqli = new mysqli("localhost", "lunar_casino", "******", "lunar_casino");
if(isset($_POST['submit'])){
$error = array();
if(empty($error)){
$bonus = $_POST['bonus'];
$deposit = $_POST['deposit'];
$offers = $_POST['offers'];
$link = $_POST['link'];
$name = $_POST['logo'];
$q = $mysqli->query("INSERT INTO `lunar_casino`.`casino` VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NULL)");
if(!$q){
echo "<font color='red'><b>There has been an error with our database! Please contact the website administrator!</b></font><br /><br />";
} else {
echo "<font color='green'><b>You have successfully added the casino!</b></font><br /><br />";
}
} else {
echo "<font color='red'><b>There were ".count($error)." errors in your form:</b></font><br />";
foreach($error as $err){
echo "<b>".$err."</b><br />";
}
echo "<br />";
}
}
Structure of Database:
数据库结构:
If you need more information just let me know!
如果您需要更多信息,请告诉我们!
By the way, the way I know the error is in the query is because I checked if(!$q) and made it display an error message if the query can't be done, and it displays the error message on the page.
顺便说一句,我在查询中知道错误的方式是因为我检查了是否(!$ q)并且如果查询无法完成则显示错误消息,并且它在页面上显示错误消息。
Any ideas why its not working? Also I left out date from the query because I don't know how to add the current date:time into the query.
任何想法为什么它不工作?此外,我从查询中遗漏了日期,因为我不知道如何将当前日期:时间添加到查询中。
If anyone could help with either of these issues please let me know! :)
如果有人可以帮助解决这些问题,请告诉我们! :)
2 个解决方案
#1
0
I think the problem is that you set NULL
the date column. Try NOW()
instead of NULL
:
我认为问题是你设置NULL日期列。尝试NOW()而不是NULL:
$q = $mysqli->query("INSERT INTO `lunar_casino`.`casino` VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NOW())");
#2
0
Your error here is isn't very clear. Here are some debugging options you can try:
你在这里的错误不是很清楚。以下是您可以尝试的一些调试选项:
Name the fields
命名字段
$q = $mysqli->query("INSERT INTO `lunar_casino`.`casino` VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NULL)");
to
$q = $mysqli->query("INSERT INTO `lunar_casino`.`casino`(field1, field2...) VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NULL)");
Save your query to a string and print it out. (Gordon Linoff)
将查询保存为字符串并将其打印出来。 (戈登林诺夫)
echo "INSERT INTO `lunar_casino`.`casino` VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NULL)"
before the query. This can show you what PHP is making for MySQL to feed on.
在查询之前。这可以向您展示PHP为MySQL提供的功能。
Check for errors
检查错误
if ($mysqli->connect_errno) { //check connection error
printf("Connect failed: %s\n", $mysqli->connect_error); //check query error
exit();
}
#1
0
I think the problem is that you set NULL
the date column. Try NOW()
instead of NULL
:
我认为问题是你设置NULL日期列。尝试NOW()而不是NULL:
$q = $mysqli->query("INSERT INTO `lunar_casino`.`casino` VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NOW())");
#2
0
Your error here is isn't very clear. Here are some debugging options you can try:
你在这里的错误不是很清楚。以下是您可以尝试的一些调试选项:
Name the fields
命名字段
$q = $mysqli->query("INSERT INTO `lunar_casino`.`casino` VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NULL)");
to
$q = $mysqli->query("INSERT INTO `lunar_casino`.`casino`(field1, field2...) VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NULL)");
Save your query to a string and print it out. (Gordon Linoff)
将查询保存为字符串并将其打印出来。 (戈登林诺夫)
echo "INSERT INTO `lunar_casino`.`casino` VALUES(NULL, '$bonus', '$deposit', '$offers', '$link', '$logo', '$name', NULL)"
before the query. This can show you what PHP is making for MySQL to feed on.
在查询之前。这可以向您展示PHP为MySQL提供的功能。
Check for errors
检查错误
if ($mysqli->connect_errno) { //check connection error
printf("Connect failed: %s\n", $mysqli->connect_error); //check query error
exit();
}