php - inputting image links into mysql -


so i've hit bit of snag. i'm working on form uploads image file ftp , creates entry mysql link image column used organize , order images.

i'm getting following error:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'order) values( '', '../tattoo/1.jpg', '6')' @ line 1

i have tried placing '' around values , not , still same message. i'm sure solution simple , i'm tired , have been staring @ long. here code

    <?php    // configuration - options       $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // these types     of file pass validation.       $max_filesize = 524288; // maximum filesize in bytes (currently 0.5mb).       $upload_path = '../tattoo/'; // place files uploaded to.     $filename = $_files['userfile']['name']; // name of file (including file extension).    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // extension filename.     // check if filetype allowed, if not die , inform user.    if(!in_array($ext,$allowed_filetypes))       die('the file attempted upload not proper format, please submit .jpg, .gif, .bmp, or .png');     // check filesize, if large die , inform user.    if(filesize($_files['userfile']['tmp_name']) > $max_filesize)       die('the file attempted upload large. max file size 0.5mb');     // check if can upload specified path, if not die , inform user.    if(!is_writable($upload_path))       die('you cannot upload specified directory, please chmod 777.');     // upload file specified path.    if(move_uploaded_file($_files['userfile']['tmp_name'],$upload_path . $filename))          echo 'your file upload successful, view file <a href="' . $upload_path . $filename . '" title="your file">here</a><p>'; // worked.       else          echo 'there error during file upload.  please try again.'; // failed :(.  // add picture listing mysql      //include database connection details     include('config.php');      //connect mysql server     $mysql = mysql_connect(db_host, db_user, db_password, db_database);     if(!$mysql) {         die('failed connect server: ' . mysql_error());     }     mysql_select_db("sonyaopal", $mysql) or die( "unable select database" .  mysql_error());  $result = mysql_query ( "select count(*) tattoos" );  $location = '' . $upload_path . $filename . ''; $order = $result+1;       $inslisting_sql = "insert tattoos (id, location, order) values('',              '".mysql_real_escape_string("$location")."',             '".mysql_real_escape_string("$order")."')";      $inslisting_res = mysql_query($inslisting_sql, $mysql)             or die(mysql_error($mysql)); ?> 

you can edit below code , try it:

<?php  //getting filename of image file. $filename = $_files["image"]["name"];  //directory name stored. $path = "data/mydata";  //uploading image file image file name directory. if(move_uploaded_file($_files["image"]["tmp_name"],$path."/".$filename) {  //if image stored success directory going store database.  //the real path filename.  $mysql_path = $path."/".$filename;  //sql query executed. $sql = "insert `tablename`(`filename`,`path`) values ('$filename','$mysql_path')";  //executing query. if(mysql_query($sql)) { echo 'path inserted database'; } else { echo 'path not inserted database'; } } else { echo 'file not uploaded'; } ?> 

the error in insert query did run query manually , checked..


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -