Помогите разобрать код на косточки. (Можно просто пояснить, что каждая строка в этом коде означает, что-бы понять как это работает). И помочь исправить !
if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
{
$id = $_GET['edit_id'];
$stmt_edit = $DB_con->prepare('SELECT name, name_ru, description, description_ru, price, image FROM colianuri WHERE ID =:uid');
$stmt_edit->execute(array(':uid'=>$id));
$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
extract($edit_row);
}
else
{
header("Location: admin.php");
}
Вылазит вот такая ошибка:
Warning: extract() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\sam2\editform.php on line 13
Переменная
$edit_row
приходит BoolenFalse, хотя в ней должен содержаться массив. Что не так? Всё работало, и в один момент перестало.
Вот исходник edit.php:
<?php
error_reporting( ~E_NOTICE );
require_once 'dbconfig.php';
if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
{
$id = $_GET['edit_id'];
$stmt_edit = $DB_con->prepare('SELECT name, name_ru, description, description_ru, price, image FROM colianuri WHERE ID =:uid');
$stmt_edit->execute(array(':uid'=>$id));
$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
extract($edit_row);
}
else
{
header("Location: admin.php");
}
if(isset($_POST['btn_save_updates']))
{
$name = $_POST['name'];// name
$name_ru = $_POST['name_ru'];// name
$description = $_POST['description'];// description
$description_ru = $_POST['description_ru'];// description
$price = $_POST['price'];
$imgFile = $_FILES['image']['name'];
$tmp_dir = $_FILES['image']['tmp_name'];
$imgSize = $_FILES['image']['size'];
if($imgFile)
{
$upload_dir = 'image/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
$image = rand(1000,1000000).".".$imgExt;
if(in_array($imgExt, $valid_extensions))
{
if($imgSize < 5000000)
{
unlink($upload_dir.$edit_row['image']);
move_uploaded_file($tmp_dir,$upload_dir.$image);
}
else
{
$errMSG = "Sorry, your file is too large it should be less then 5MB";
}
}
else
{
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
}
else
{
// if no image selected the old image remain as it is.
$userpic = $edit_row['image']; // old image from database
}
// if no error occured, continue ....
if(!isset($errMSG))
{
$stmt = $DB_con->prepare('UPDATE colianuri
SET name=:uname,
name_ru=:uname_ru,
description=:ujob,
description_ru=:ujob_ru,
price=:uprice,
image=:upic
WHERE ID=:uid');
$stmt->bindParam(':uname',$name);
$stmt->bindParam(':uname_ru',$name_ru);
$stmt->bindParam(':ujob',$description);
$stmt->bindParam(':ujob_ru',$description_ru);
$stmt->bindParam(':upic',$image);
$stmt->bindParam(':uid',$id);
if($stmt->execute()){
?>
<script>
alert('Successfully Updated ...');
window.location.href='admin.php';
</script>
<?php
}
else{
$errMSG = "Sorry Data Could Not Updated !";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Adminca</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
<!-- custom stylesheet -->
<link rel="stylesheet" href="style.css">
<!-- Latest compiled and minified JavaScript -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="jquery-1.11.3-jquery.min.js"></script>
</head>
<body>
<div class="page-header">
<h1 class="h2">update product. <a class="btn btn-default" href="admin.php"> all products </a></h1>
</div>
<div class="clearfix"></div>
<form method="post" enctype="multipart/form-data" class="form-horizontal">
<?php
if(isset($errMSG)){
?>
<div class="alert alert-danger">
<span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
</div>
<?php
}
?>
<table class="table table-bordered table-responsive">
<tr>
<td><label class="control-label">Name RO.</label></td>
<td><input class="form-control" type="text" name="name" value="<?php echo $name; ?>" required /></td>
</tr>
<tr>
<td><label class="control-label">Name RU.</label></td>
<td><input class="form-control" type="text" name="name_ru" value="<?php echo $name_ru; ?>" required /></td>
</tr>
<tr>
<td><label class="control-label">Descriptie RO.</label></td>
<td><input class="form-control" type="text" name="description" value="<?php echo $description; ?>" required /></td>
</tr>
<tr>
<td><label class="control-label">Descriptie RU.</label></td>
<td><input class="form-control" type="text" name="description_ru" value="<?php echo $description_ru; ?>" required /></td>
</tr>
<tr>
<td><label class="control-label">Price.</label></td>
<td><input class="form-control" type="text" name="price" value="<?php echo $price; ?>" required /></td>
</tr>
<tr>
<td><label class="control-label">Photo.</label></td>
<td>
<p><img src="image/<?php echo $image; ?>" height="150" width="150" /></p>
<input class="input-group" type="file" name="image" accept="image/*" />
</td>
</tr>
<tr>
<td colspan="2"><button type="submit" name="btn_save_updates" class="btn btn-default">
<span class="glyphicon glyphicon-save"></span> Update
</button>
<a class="btn btn-default" href="admin.php"> <span class="glyphicon glyphicon-backward"></span> cancel </a>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Таблица БД
Весь интернет перерыл. На форумы писал. Все РАЗВОДЯТ руками! Никто не знает в чём проблема.