gpt4 book ai didi

php - PHP 中的 Sql 语句未插入数据库,但未给出错误

转载 作者:行者123 更新时间:2023-11-29 21:32:33 26 4
gpt4 key购买 nike

感谢这个网站,我可以设法解决我的问题,但是我的语句没有在我的数据库上执行,但是当我将其复制并直接粘贴到我的数据库时,它插入时没有任何问题。这是我的代码:

<?php
$ip = "***"; //MySQL Server IP
$user = "***"; //MySQL user
$pw = "***"; //MySQL password
$db = "***"; //Database
$sql_filter = "";


$con = mysqli_connect($ip, $user, $pw, $db);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}

function register()
{
$username = $_POST[username];
$vorname = $_POST[vorname];
$nachname = $_POST[nachname];
$geschlecht = $_POST[geschlecht];
$geburtsdate = $_POST[geburtsdatum];
$password = $_POST[password];
$email = $_POST[email];

if($email!="" and $password!="" and $username!="" and $password==$_POST["password_confirm"])
{

$sql_filter = "INSERT INTO `tblUser`(`UserID`, `UserName`, `Vorname`, `Nachname`, `EMail`, `Geschlecht`,`Password`) VALUES ('','$username','$vorname','$nachname','$email','$geschlecht','$password')";

$_SESSION['filter'] = $sql_filter;
$page_query = mysqli_query($con, $_SESSION['filter']);
$page_nums = mysqli_num_rows($page_query);

//header('Location: index.php');

echo $sql_filter;
echo $_SESSION['filter'];
}
else
{
header('Location: 404.html');
}
}

if(isset($_POST['submit']))
{
register();
}

mysqli_close($con);
?>

最佳答案

我认为问题是你的 $con 在函数 register() 中未定义。因此,将其添加到函数的开头:

function register()
{
global $con;
... // the rest of your function
}

关于php - PHP 中的 Sql 语句未插入数据库,但未给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35147797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com