gpt4 book ai didi

php - mysqli_query() 上的空白页;?

转载 作者:行者123 更新时间:2023-11-29 23:01:05 24 4
gpt4 key购买 nike

我正在制作一个基本的歌曲推荐网站,并且设置了一个表单,该表单可指向一个包含以下确切代码的页面:

<?php
ini_set('display_errors',1);
ob_start();
session_start();

$host = "localhost";
$user = "root";
$pass = "MYPASS";
$db = "tts";

$conn = mysqli_connect($host, $user, $pass, $db);

$song = $_POST['song'];
$artist = $_POST['artist'];
$album = $_POST['album'];
$linkitunes = $_POST['linkitunes'];
$artwork = $_POST['artwork'];

$song = stripslashes($song);
$artist = stripslashes($artist);
$album = stripslashes($album);
$linkitunes = stripslashes($linkitunes);
$artwork = stripslashes($artwork);

$sql = "INSERT INTO recommendation (user_id, song, artist, album, linkitunes, artwork, rating)";
$sql = $sql . "VALUES ($_SESSION['id'], '$song', '$artist', '$album', '$linkitunes', '$artwork', '$rating');";

print "Hello.";

$result = mysqli_query($sql) or die("Fail");

ob_flush();
?>

它总是显示“你好”。字符串,直到我添加 $sql 值。我认为代码语法有问题,但不确定。尝试过很多变体。以防万一,我还添加了表单代码:

<form action="recommend-action.php" method="POST">
<div id="noP" align="center">
<h2>Make a new Recommendation</h2>
<p>Please <a href="song-search.php">search</a> for your song before you recommend it.</p>
</div>
<div align="center">
<input required name="song" type="text" placeholder="Song" maxlength="50"></input>
<input required name="artist" type="text" placeholder="Artist" maxlength="50"></input>
<input name="album" type="text" placeholder="Album" maxlength="50"></input>
<input name="artwork" type="url" placeholder="Artwork" maxlength="500"></input>
<input name="linkitunes" type="url" placeholder="Link in iTunes" maxlength="500"></input>
<input id="submit" type="submit" value="Recommend"></input>
</div>

最佳答案

你应该执行这个...

        $result = mysqli_query($con,$sql); or die("Fail");

关于php - mysqli_query() 上的空白页;?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28493096/

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