This question already has answers here:
Parse errors are not displayed
                                
                                    (8个答案)
                                
                        
                                4年前关闭。
            
                    
我正在建立一个基本的歌曲推荐站点,并且建立了一个表单,该表单会导致页面上包含以下确切代码:

<?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/

10-13 00:59