gpt4 book ai didi

php - 2 尝试使用mysql将数据插入数据库时​​出错

转载 作者:行者123 更新时间:2023-11-29 08:19:06 25 4
gpt4 key购买 nike

我很抱歉这可能是一个愚蠢的问题,但我是新手,我在谷歌上找不到答案。这段代码给了我两个错误:

Warning: mysql_query() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Music Collection\submitmusic.php on line 27

Warning: mysql_error() expects parameter 1 to be resource, string given in C:\xampp\htdocs\Music Collection\submitmusic.php on line 29

不知道如何解决这个问题,请帮助我。

<html>
<head>
<title> Music Collection </title>
</head>

<body>
<?php
$con = "mysql_connect ('localhost','root','','music')";
// Check Connection
if (mysql_errno())
{
echo "Failed to connect: " . mysql_error();
}
else
{
$title = $_POST['title'];
$artist = $_POST['artist'];
$album = $_POST['album'];
$location = $_POST['location'];
$media = $_POST['media'];

$sql = mysql_query("INSERT INTO entries (Title, Artist, Album, Location, Media) VALUES ('$title','$artist','$album','$location','$media')");

if (!mysql_query($con,$sql))
{
die ('Error: ' . mysql_error($con));
}
else
{
echo "record added!";
}
}
mysql_close($con);
?>

</body>
</html>

最佳答案

删除双引号:

$con = "mysql_connect ('localhost','root','','music')";

关于php - 2 尝试使用mysql将数据插入数据库时​​出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19930929/

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