It saves without an error, but it still doesnt reflect in my database
16lz
2021-01-22
I'm a beginner and i have a few problems with my codes.
我是初学者,我的代码有一些问题。
Every things seems to be ok with my codes because it doesn't give me any errors, but after saving, i don't get the data reflected in my database.
我的代码似乎一切正常,因为它没有给我任何错误,但保存后,我没有得到数据反映在我的数据库中。
Here is the code:
这是代码:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "election";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sqli = "INSERT INTO `election`.`registration` (`Reg_Num`, `Full_Name`, `Level`, `Gender`) VALUES ('$_POST[Reg_Num]', '$_POST[Full_Name]', '$_POST[Level]', '$_POST[Gender]');";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form</title>
</head>
<body>
<title>Form Submitted</title>
<p></p>
<p>Thanks for Registering</p>
<p></p>
<a href="vote.php">Register another student</a><br />
</body>
</html>
Please help!
3 个解决方案
#1
1
You need to actually execute the INSERT
statement, e.g.
您需要实际执行INSERT语句,例如
$sqli = "INSERT INTO `election`.`registration` (`Reg_Num`, `Full_Name`, `Level`, `Gender`) VALUES ('$_POST[Reg_Num]', '$_POST[Full_Name]', '$_POST[Level]', '$_POST[Gender]');";
if ($conn->query($sqli) === TRUE) {
echo "insert succeeded";
} else {
echo "Error: " . $conn->error;
}
更多相关文章
- php二维码/26行代码制作php二维码phpqrcode加grafika水印
- php分页代码的问题,显示了两个当前页码,求大神解答
- PHP开发微信支付代码及支付通知处理
- 几个有用的php字符串过滤,转换函数代码
- mysqli类使用预处理语句不返回任何数据
- 在Web Page中包含PHP代码
- php mail函数一段好的代码
- 用于上传多个文件的PHP代码
- (phpQuery)对网站产品信息采集代码的优化