Problem with the Insert Function in PHP for mySQL

Discussion in 'Programming' started by Majo0od, Oct 28, 2009.

  1. #1
    Hey guys,

    There is a problem with my insert function in php...

    $vid_title = $_POST['vid_title'];
    $vid_desc = $_POST['vid_description'];
    $vid_cat = $_POST['vid_cat'];
    $vid_usr_ip = $_SERVER['REMOTE_ADDR'];
    $vid_file = $_FILES['vid_file'];

    $query = "INSERT INTO videos (Username, Title, Description, Category, PageURL, FilePath, Thumbnail, Rating, Views, IPAddress) VALUES ('".$details[0]."', '".$_POST['vid_title']."', '".$_POST['vid_description']."', '".$_POST['vid_cat']."', '../../videos/'".time()."'/', 'videos/'".time()."'/video.flv, 'videos/'".time()."'/'".$_FILES['vid_file']."', '', '', '".$vid_usr_ip."')";

    mysql_query($query);

    The site says its a synax error... What do I need to do????? I already connected to my DB and all, whats wrong? Also don't mind the "$details[0]; function, that isn't the problem...


    Thanks in advance,
    Majo0od
     
    Majo0od, Oct 28, 2009 IP
  2. eamong

    eamong Well-Known Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    108
    #2
    post full error
    mysql_error()
    or
    print query and run it manually using phpmyadmin or something alike
     
    eamong, Oct 28, 2009 IP
  3. Majo0od

    Majo0od Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    this is the error:

    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 '1256759783'/', 'videos/'1256759783'/video.flv, 'videos/'1256759783'/'Array', '',' at line 1

    how is that possible? I did this type of code before...
     
    Majo0od, Oct 28, 2009 IP
  4. Birokrat

    Birokrat Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    You should remove double quotes and dots from you query string, you dont need them.

    $query = "INSERT INTO videos (Username, Title, Description, Category, PageURL, FilePath, Thumbnail, Rating, Views, IPAddress) VALUES ('$details[0]', '$_POST['vid_title']', '$_POST['vid_description']', '$_POST['vid_cat']', '../../videos/'time()'/', 'videos/'time().'/video.flv, 'videos/'time()'/'$_FILES['vid_file']', '', '', '$vid_usr_ip')";
     
    Birokrat, Oct 28, 2009 IP
  5. Majo0od

    Majo0od Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    still didn't work.....

    error:

    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 'time()'/', 'videos/'time()'/video.flv, 'videos/'time()'/'Array', '', '', '69.41.' at line 1
     
    Majo0od, Oct 28, 2009 IP
  6. eamong

    eamong Well-Known Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    108
    #6
    dont use 'time()' if its already in quotes
    use something like this
    'videos/".time()."/'".$_FILES['vid_file']."'
    remove single quotes surrounding time()
     
    eamong, Oct 29, 2009 IP
  7. ManyThings

    ManyThings Greenhorn

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #7
    put

    so we can look at the generated SQL!
     
    ManyThings, Oct 30, 2009 IP