SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Files not inserting to Mysql

    Hi,

    Got a problem with some lines of a code where after a file upload it should insert data into the connected database for the files to show up on the mainpage but it doesn't. The file upload just fine into FTP tho.

    The code itself is the following:

    $query = "INSERT INTO videos SET USERID='$_SESSION[USERID]', title='".mysql_real_escape_string($thetitle)."', description='".mysql_real_escape_string($thedesc)."', tags='".mysql_real_escape_string($thetags)."', categories='".mysql_real_escape_string($thecat)."', filesize='$space', public='".mysql_real_escape_string($thepublic)."', time_added='".time()."', date_added='".date("Y-m-d")."', $active, allowcomments='".mysql_real_escape_string($theallowcomments)."', allowratings='".mysql_real_escape_string($theallowratings)."', allowembeds='".mysql_real_escape_string($theallowembeds)."', allowdownloads='".mysql_real_escape_string($theallowdownloads)."'$addseriesdata, mature='".mysql_real_escape_string($themature)."'";

    $conn->execute($query);
    $videoid = mysql_insert_id();

    $original = $videoid.".".$ph;
    $videor = $config['originalvdir'].'/'.$original;

    Can anyone see anything off here?

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    First glaring issue is that you are using the incorrect SQL statement for INSERT.

    Insert query uses:
    Code:
    INSERT INTO table VALUES(x,y,z)
    or
    Code:
    INSERT INTO table(col x, col y, col z) VALUES(x,y,z)
    Update query uses:
    Code:
    UPDATE table SET col x = x, col y = y, col z = z WHERE column =  condition
    Second, if you are using PDO, you can do without mysql_insert_id() and user lastInsertId()
    Code:
    $conn->execute($query);
    $videoid = $conn->lastInsertId();
    http://www.php.net/manual/en/pdo.lastinsertid.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •