html - MySQL INSERT not inserting expected value using PHP -
i trying saved image server, have on code using php , mysql..i got error image location not appear on db following appears on table location: ''photos/" not save image name.
how can ?
here code :
// uploading image file , store specific folder & save location db $image= addslashes(file_get_contents($_files['image']['tmp_name'])); $image_name= addslashes($_files['image']['name']); move_uploaded_file($_files["image"]["tmp_name"],"photos/" . $_files["image"]["name"]); $location="photos/" . $_files["image"]["name"]; //storing path db $save=mysql_query("insert photos (location) values ('$location')");
your error handling bad. use following code instead;
foreach ($_files["image"]["error"] $key => $error) { if ($error == upload_err_ok) { $tmp_name = $_files["image"]["tmp_name"][$key]; $name = $_files["image"]["name"][$key]; $full_path = "photos/" . $name; // sure path writable move_uploaded_file($tmp_name, $full_path); $save=mysql_query("insert photos (location) values ('$full_path')"); } else { die($error); } }
Comments
Post a Comment