简体   繁体   中英

PHP Form/Mysql INSERT INTO not working

Hey I'm Trying To add some data in my table through a form .
But the form is not working or somethings wrong with my PHP code .

This is the 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>

And This is The 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");
}

Do You know What i'm doing wrong here ? i've done this before with no problems .
but it seems like i'm forgetting something this time .

You have a syntax error in your SQL query:

',$arrange'

There is a missing ' .

You can check for SQL errors by running echo mysql_error(); after the query.

Side note: The mysql_* functions you are using are becoming deprecated and will be removed from future PHP versions. Your code will stop working then. If you write new code, use mysqli_* functions or PDO instead.

You have not passed the connection variable to mysql_query function.

If you are getting the connection by some other way then do the following and see:

Just print the whole post array and see anything missing. Also print file array and see the presence of file and error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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