繁体   English   中英

PHP表单/ 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错误echo mysql_error(); 在查询之后。

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

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

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

只需打印整个帖子阵列,看看有什么遗漏。 同时打印文件数组并查看是否存在文件和错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM