开发者

Mysql file upload error?

Here is my code to upload a file. Everything is working perfect. This code uploads the file to destination folder and MySQL query work perfect and insert all data into their relative fields in database. But it is not going to the page which is mentioned in header() function. It gives me an error at the end like this

Error: please try again, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

I think it occurs when last if($exe) is executed

<?php

include('./includes/connection.p开发者_开发问答hp');

if(!$_POST['song_name']){
    header('location: pro_add.php');
    exit;
}

$path = "../upload_data/";
$uniqid = uniqid(strtotime('now'));
$uniq_name = $uniqid .'_'. $_FILES['file']['name'];

$complete_path = $path . $uniq_name;

$move = move_uploaded_file($_FILES['file']['tmp_name'],$complete_path);

if(!$move){
    echo 'Error: please try again'."<br/>";
}

$query = mysql_query("INSERT INTO products SET
    sub_cat_id='".$_POST['sub_cat_id']."',
    song_name='".$_POST['song_name']."',
    artist='".$_POST['artist']."',
    path='".$complete_path."' ");

$exe = mysql_query($query);

if($exe){
    header('location: products.php');
    exit;
}else{
    echo 'Error: please try again, <br />' . mysql_error();
}

?>


You are querying the result of your query:

$query = mysql_query('...');
$exe   = mysql_query($query);

Just replace $query = mysql_query('...'); with $exe = mysql_query('...') and it should work.

EDIT

As commenters on your question also pointed out, your script is extremely vulnerable to SQL Injection. You should read up on that before putting this online.

http://en.wikipedia.org/wiki/SQL_injection
http://php.net/manual/en/security.database.sql-injection.php


code is fine but it has only one problem. may be it has gone out of your mind...

 $query = mysql_query("INSERT INTO products SET
           sub_cat_id='".$_POST['sub_cat_id']."',
           song_name='".$_POST['song_name']."',
           artist='".$_POST['artist']."',
           path='".$complete_path."' ");

instead of this you should write

$query = "INSERT INTO products SET
          sub_cat_id='".$_POST['sub_cat_id']."',
          song_name='".$_POST['song_name']."',
          artist='".$_POST['artist']."',
          path='".$complete_path."'";

it will work fine if you replace this much of code..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜