// Getting the id of the restaurant to which we are uploading the pictures
$restaurant_id = intval($_GET['restaurant-id']);
if(isset($_POST['submit']))
{
$tmp_files = $_FILES['rest_pics']['tmp_name'];
$target_files = $_FILES['rest_pics']['name'];
$tmp_target = array_combine($tmp_files, $target_files);
$upload_dir = $rest_pics_path;
foreach($tmp_target as $tmp_file => $target_file)
{
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file))
{
$sql = sprintf("
INSERT INTO rest_pics
(branch_id, pic_name)
VALUES ('%s', '%s')"
, mysql_real_escape_string($restaurant_id)
, mysql_real_escape_string(basename($target_file)));
$result = mysql_query($sql) or die(mysql_error());
}
Ben sonraki hatayı alıyorum:
Cannot add or update a child row: a foreign key constraint fails (
rest_v2
.rest_pics
, CONSTRAINTrest_pics_ibfk_1
FOREIGN KEY (branch_id
) REFERENCESrest_branches
(branch_id
) ON DELETE CASCADE ON UPDATE CASCADE
Ancak, bu hata tamamen kaybolur ve ben sql sorgu yerine $ restaurant_id değişkeni doğrudan restoran id (14 örneğin) koyduğunuzda her şey iyi gider.
The URL am getting the id from is: http://localhost/rest_v2/public_html/admin/add-delete-pics.php?restaurant-id=2
Herhangi bir yardım lütfen?