Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何调试“您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册,以了解要使用的正确语法”_Php_Web - Fatal编程技术网

Php 如何调试“您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册,以了解要使用的正确语法”

Php 如何调试“您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册,以了解要使用的正确语法”,php,web,Php,Web,我一直在尝试更新一个实体,但我必须在更新页面上更新所有实体,否则会引发错误: 这是我的密码: // to verify if user is an admin <?php include "include/uni_header.php"?> <?php if (isset($_GET['update'])){ if ($_GET['update'] == null){ header("

我一直在尝试更新一个实体,但我必须在更新页面上更新所有实体,否则会引发错误:

这是我的密码:

// to verify if user is an admin
    <?php include "include/uni_header.php"?>
    <?php
    if (isset($_GET['update'])){
        if ($_GET['update'] == null){
            header("Location: error/error.php");
        }else{
            $hlp = $_GET['update'];
        }
    }else{
        header("Location: error/error.php");
    }
    ?>
        <!-- mail -->
    
        <div class="latest-albums">
            <div class="container">
                <h3 class="agileits_w3layouts_head"> <span>Update existing</span></h3>
                <div class="wthree_latest_albums_grids gallery">
                    <div class="col-md-9 agile_mail_grid_left">
                       // here i am trying to fetch all value & putting them on the field
                        <?php
                                $sql = "select * from music where id=$hlp";
                                $getter = mysqli_query($connection, $sql);
                                while ($row=mysqli_fetch_assoc($getter)) {
                                    $id = $row['id'];
                                    $title = $row['title'];
                                    $singer = $row['singer'];
                                    $description = $row['description'];
                                    $length = $row['length'];
                                    $relese_date = $row['relese_date'];
                                    $lyrics = $row['lyrics'];
                                    $genere = $row['genere'];
                                    $songs = $row['songs'];
                                    $thumbnail = $row['thumbnail'];
                                    $language = $row['language'];
                                    $album_tag = $row['album_tag'];
                                    $youtube_id = $row['youtube_id'];
                                    $feature_tag = $row['feature_tag'];
                                }
                        ?>
                        // trying to update
                        <?php
                        if (isset($_POST['submits'])){
                            $title = $_POST['name'];
                            $singer = $_POST['singer'];
                            $description = $_POST['description'];
                            $length = $_POST['length'];
                            $date = $_POST['release_date'];
                            $lyrics = $_POST['lyrics'];
                            $category = $_POST['cat'];
                            $language = $_POST['cat1'];
                            $youtube = substr($_POST['youtube'], 17);
                            $album = $_POST['album'];
    
                            //thumbnail
                            $p_image = $_FILES['images']['name'];
                            $post_image_temp = $_FILES['images']['tmp_name'];
                            move_uploaded_file($post_image_temp, "thumbnail/$p_image");
    
                            //songs
                            $upload_file = $_FILES['files']['name'];
                            $temps = $_FILES['files']['tmp_name'];
                            move_uploaded_file($temps, "songs/$upload_file");
                            //query
                                $query = "update music set title='{$title}', singer='{$singer}', description='{$description}', length='{$length}', relese_date='{$date}', lyrics='{$lyrics}', genere={$category}, songs='{$upload_file}', thumbnail='{$upload_file}', language={$language}, album_tag='{$album}', youtube_id='{$youtube}' where id={$hlp}";
                                $sender = mysqli_query($connection, $query);
                                echo "error".mysqli_error($connection);
    
    
    
                        }
                        ?>
                       // pushing previously pulled value as user can see old values, it helps to update.
                        <form action="" method="post" enctype="multipart/form-data">
                            <label for="name">Enter Song Title</label>
                            <input type="text" name="name" placeholder="Name" value="<?php echo $title; ?>"><br>
    
                            <label for="email">Singer</label>
                            <input type="text" name="singer" placeholder="Singer" value="<?php echo $singer; ?>"><br>
    
                            <label for="description">Description</label>
                            <input type="text" name="description" placeholder="Description" value="<?php echo $description; ?>"><br>
    
                            <label for="length">Run Time</label>
                            <input type="text" name="length" placeholder="Run Time" value="<?php echo $length; ?>"><br>
    
                            <label for="images">Upload the song</label>
                            <input type="file" name="files" class="btn btn-default">
    
                            <label for="album">Album name</label>
                            <input type="text" name="album" placeholder="Album name" value="<?php echo $album_tag; ?>"><br>
    
                            <label for="youtube">Paste the Short URL only</label>
                            <input type="text" name="youtube" placeholder="ex: https://youtu.be/xxxxx" value="<?php echo $youtube_id; ?>"><br>
                            *This field only accepts SHORT URL <b>(open the song vid->share->copy link)</b>
                            <br><br>
    
                            <label for="country1">Choose Language</label>
                            <div class="btn-group">
                                <select id="country1" class="dropdown" name="cat1">
                                    <?php
                                            $sql1 = "select * from language where id=$language";
                                            $getter1 = mysqli_query($connection,$sql1);
                                            while ($r=mysqli_fetch_assoc($getter1)){
                                                $language=$r['language'];
                                            }
                                    ?>
                                    <option class="dropdown-header" value=""><?php echo $language; ?></option>
                                    <?php
                                    $querys = "select * from language";
                                    $sends = mysqli_query($connection, $querys);
    
                                    while ($row = mysqli_fetch_assoc($sends)) {
                                        $id = $row['id'];
                                        $language = $row['language'];
    
                                        echo "<option class='dropdown-item' value='{$id}'>{$language}</option>";
                                    }
                                    ?>
                                </select>
    
                            </div>
                            <br><br>
    
                            <label for="release_date">Release Date</label>
                            <input type="date" autocomplete="off" name="release_date" id="date" placeholder="Relese Date" value="<?php echo $relese_date; ?>"><br>
    
                            <br>
                            <label>Upload A Thumbnail Picture</label>
                            <input type="file" name="images" class="btn btn-default">
                            <br>
    
                            <label>Post the lyrics</label>
                            <textarea name="lyrics" placeholder="Description of the book"  id = "body"></textarea>
                            <br>
    
                            <label for="Genre">Choose Genre</label>
                            <div class="btn-group">
                                <select id="country" class="dropdown" name="cat">
                                    <option class="dropdown-header" value=""><?php echo $genere; ?></option>
                                    <?php
                                    $querys = "select * from category";
                                    $sends = mysqli_query($connection, $querys);
    
                                    while ($row = mysqli_fetch_assoc($sends)) {
                                        $id = $row['id'];
                                        $category = $row['title'];
    
                                        echo "<option class='dropdown-item' value='{$id}'>{$category}</option>";
                                    }
                                    ?>
                                </select>
    
                            </div>
    
                            <br><br>
    
                            <input type="submit" value="Post Your Song Now" name="submits">
                        </form>
                    </div>
    
                    <div class="clearfix"> </div>
                </div>
            </div>
        </div>
        <!-- //mail -->
    <?php include "include/about_footer.php"?>
当我单击“提交”时,会出现如下错误:

您的SQL语法有错误;检查手册 对应于要使用的正确语法的MariaDB服务器版本 在第1行的“album_tag='fefef222'附近,youtube_id=where id=19”

我的数据库结构是:

创建表格音乐id int3 NOT NULL、标题varchar255 NOT NULL、歌手varchar255 NOT NULL、描述文本NOT NULL、长度varchar255 NOT NULL、发布日期varchar255 NOT NULL、喜欢int3 NOT NULL、歌词文本NOT NULL、genere int3 NOT NULL、歌曲文本NOT NULL、缩略图文本NOT NULL、语言int3 NOT NULL、唱片集标签varchar255 NOT NULL、,youtube_id varchar255 NOT NULL,feature_tag varchar255 NOT NULL默认“general”引擎=InnoDB默认字符集=latin1

创建表语言id int11 NOT NULL,语言varchar255 NOT NULL ENGINE=InnoDB DEFAULT CHARSET=latin1


我的错在哪里?

实际上“语言”是一个整数字段。。。我也应该用引号吗?不,不要用引号。我能看看你的数据库结构吗?好的,等等。如有必要,将使用代码修复来回答“cat1”字段是否有值?选项似乎有value=On Stack Overflow,我们鼓励回答者添加一些解释,而不是仅使用代码来回答。我们认为,一些解释性的文本使答案对未来的读者更有用。
<label for="country1">Choose Language</label>
<div class="btn-group">
    <select id="country1" class="dropdown" name="cat1">
        <?php
                $sql1 = "select * from language where id=$language";
                $languageId = $language;

                $getter1 = mysqli_query($connection,$sql1);
                while ($r=mysqli_fetch_assoc($getter1)){
                    $language=$r['language'];
                }
        ?>
        <!-- you have an empty value which would result to 
            language =, album_tag='fefef222', 
             -->
        <!-- which is wrong.. -->


        <!-- you need the id, just incase the user doesn't alter the select box for another language -->
        <!-- this is the default language -->
        <option class="dropdown-header" value="<?=$languageId?>"><?php echo $language; ?></option>
        <?php
        $querys = "select * from language";
        $sends = mysqli_query($connection, $querys);

        while ($row = mysqli_fetch_assoc($sends)) {
            $id = $row['id'];
            $language = $row['language'];

            echo "<option class='dropdown-item' value='{$id}'>{$language}</option>";
        }
        ?>
    </select>

</div>
<br><br>


<!-- now your  query would run fine -->
<?php

$query = "update music set title='{$title}', singer='{$singer}', description='{$description}', length='{$length}', relese_date='{$date}', lyrics='{$lyrics}', genere={$category}, songs='{$upload_file}', thumbnail='{$upload_file}', language={$language}, album_tag='{$album}', youtube_id='{$youtube}' where id={$hlp}";

?>