gpt4 book ai didi

PHP 连接 MySQL 数据库时出错

转载 作者:搜寻专家 更新时间:2023-10-30 23:29:26 26 4
gpt4 key购买 nike

我试图通过 php 代码连接到我的本地数据库,但出现此错误:

Syntax error, unexpected '$result' (T_VARIABLE), expecting ',' or ')'

我不明白问题出在哪里。这是我的代码:

    <?php
$hostname = "localhost";
$username = "root";
$password = "";

$databaseName = "newspage";

$dbConnected = @mysqli_connect($hostname, $username, $password);

$dbSelected = @mysqli_connect($databaseName, $dbConnected);

$query = "INSERT INTO news(titolo, testo, data)VALUES('".$_POST["titolo"]."', '".$_POST["testo"]."', NOW())";
$result = @mysqli_query($query);
if(!$result){
echo("Errore aggiunta news: " . mysqli_error(mysqli $result));
exit();
}

else {
mysqli_close(mysqli $dbConnected);
echo('News caricata!<br><a href="add.php">Clicca qui</a> per aggiungere altre news.<br><a href="edit.php">Clicca qui</a> per apportare modifiche alle news.<br><a href="../index.php">Clicca qui</a> per tornare alla pagina principale.');
}
?>

最佳答案

您的问题出在这一行:

echo("Errore aggiunta news: " . mysqli_error(mysqli $result));

应该是:

echo("Errore aggiunta news: " . mysqli_error($result));

关于PHP 连接 MySQL 数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51315125/

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