PHP Form/Mysql INSERT INTO不起作用


PHP Form/Mysql INSERT INTO not working

嘿,我正试图通过表单在表中添加一些数据
但是表单不起作用,或者我的PHP代码出了问题。

这是HTML

        <form action="upload.php" method="post" enctype="multipart/form-data" name="subform" id="subform" class="forms" role="form" >
        <label>    
        <input name="title" id="title" type="text" class="form-control" placeholder="put the title here">
        </label>
        <label>    
        <input name="singer" id="singer" type="text" class="form-control" placeholder="Artist / Band">
        </label>
        <label>    
        <input name="songname" id="songname" type="text" class="form-control" placeholder="Song Name">
        </label>
        <label>
        <input name="lyrics" id="lyrics" type="text" class="form-control" placeholder="Lyrics">
        </label>
        <label>    
        <input name="arrange" id="arrange" type="text" class="form-control" placeholder="Arrangement By ?">
        </label>
        <label>    
        <input name="channel" id="channel" type="text" class="form-control" placeholder="Channel">
        </label>
        <label>
        <input name="dllink" id="dllink" type="text" class="form-control" placeholder="Download Link">
        </label>
        <label>
        <select name="category" id="category" class="form-control">
        <option>Pop</option>
        <option>Rock</option>
        <option>Rap</option>
        <option>Classic</option>
        </select>
        </label>
        <label><input name="cover" id="cover" type="file" class="form-control"
        placeholder="Cover"></label>
        <div class="submit-btn">
        <input type="submit" class="Btn_submit" id="submit" name="button" />
        </div>
        </form>

这就是PHP:

 if(isset($_POST['title'])){
$title = mysql_real_escape_string($_POST['title']);
$category = mysql_real_escape_string($_POST['category']);
$singer = mysql_real_escape_string($_POST['singer']);
$songname = mysql_real_escape_string($_POST['songname']);
$arrange = mysql_real_escape_string($_POST['arrange']);
$lyrics = mysql_real_escape_string($_POST['lyrics']);
$dllink = mysql_real_escape_string($_POST['dllink']);
$channel = mysql_real_escape_string($_POST['channel']);
$sql = mysql_query("INSERT INTO songs (title, category, singer, sname, arrangement, lyrics, download, channel, reldate) VALUES('$title','$category','$singer','$songname',$arrange','$lyrics','$dllink','$channel',now())");
$sid = mysql_insert_id();
$newname = "$sid.jpg";
move_uploaded_file($_FILES['cover']['tmp_name'], "../covers/$newname");
header("location: upload.php");
}

你知道我在这里做错了什么吗?我以前做过,没有遇到任何问题
但这次我好像忘了什么。

您的SQL查询中存在语法错误:

',$arrange'

缺少'

您可以在查询后运行echo mysql_error();来检查SQL错误。

附带说明:您正在使用的mysql_*函数正在被弃用,并且将从未来的PHP版本中删除。届时,您的代码将停止工作。如果编写新代码,请改用mysqli_*函数或PDO。

您尚未将连接变量传递给mysql_query函数。

如果你通过其他方式获得连接,请执行以下操作并查看:

只需打印整个post数组,即可查看缺少的内容。同时打印文件数组并查看文件和错误的存在。