php - bindValue with FILE and POST variables into SQL DB -
i can't seem of these variables post database. works when leave out $_post
of $file_desc
. of $_file
variables pass through database. here's code grabbing variables:
$file_name = $_files['image']['name']; $tmp = explode('.', $file_name); $file_ext = strtolower(end($tmp)); $file_size = $_files['image']['size']; $file_tmp = $_files['image']['tmp_name']; $file_error = $_files['image']['error']; $file_desc = nl2br($_post['desc']);
and here's code running query:
$query = $pdo->prepare('insert upload (name, type, size, desc) values (?, ?, ?, ?)'); $query->bindvalue(1, $file_name); $query->bindvalue(2, $file_ext); $query->bindvalue(3, $file_size); $query->bindvalue(4, $file_desc); $query->execute();
desc
mysql keyword, used sort selected rows in descending order. in case mysql thinks it's keyword , not field name. make understand it's field - should put in apostrophes:
$query = $pdo->prepare('insert upload (name, type, size, `desc`) values (?, ?, ?, ?)');
also advice learn debugging , pay attention errors returned: bet mysql told "wrong syntax near desc @ line 1".
Comments
Post a Comment