Le formulaire ne met pas à jour les données
Posté : 10 juil. 2016, 20:54
Bonjour, pouvez-vous s'il vous plait me dire pourquoi il ne veut pas réagir ?
FORMULAIRE
FORMULAIRE
<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
include_once 'include/admin_processes.php';
include('db.php');
$Admin_Process = new Admin_Process;
$Admin_Process->check_status($_SERVER['SCRIPT_NAME']);
$edit = $Admin_Process->edit_item_inventory($_POST, $_POST['edit']);
$id=$_GET['id'];
$sql=mysql_query("select * from inventory WHERE id='".$id."'");
while($row=mysql_fetch_array($sql))
{
$company=$row['company'];
$item=$row['item'];
$sku=$row['sku'];
$glcode=$row['glcode'];
$qtyalert=$row['qtyalert'];
$notes=$row['notes'];
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']."?id=".$_GET['id']; ?>" enctype="multipart/form-data">
<div class="form-group">
<label for="company">Company</label>
<input name="company" type="text" class="form-control" value="<?php echo $company; ?>" id="company" />
</div>
<div class="form-group">
<label for="item">Item</label>
<input name="item" type="text" class="form-control" value="<?php echo $item; ?>" id="item" />
</div>
<div class="form-group">
<label for="image">Image</label>
<input type="file" name="image" id="image" />
</div>
<div class="form-group">
<label for="sku">Part# | SKU</label>
<input name="sku" type="text" value="<?php echo $sku; ?>" class="form-control" id="sku" />
</div>
<div class="form-group">
<label for="glcode">GL-Code</label>
<input name="glcode" type="text" value="<?php echo $glcode; ?>" class="form-control" id="glcode" />
</div>
<div class="form-group">
<label for="qtyalert">Alert (Remaining)</label>
<input name="qtyalert" type="text" value="<?php echo $qtyalert; ?>" class="form-control" id="qtyalert" />
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea class="form-control" rows="2" id="notes"><?php echo $notes; ?></textarea>
</div>
<button name="edit" type="submit" class="btn btn-default">Update</button>
</form>
PHP
function edit_item_inventory($post, $process) {
if(isset($process)) {
$company = $post['company'];
$item = $post['item'];
$image = $post['image'];
$sku = $post['sku'];
$glcode = $post['glcode'];
$qtyalert = $post['qtyalert'];
$notes = $post['notes'];
if((!$company) || (!$item) || (!$sku) || (!$glcode) || (!$qtyalert)) {
return "<div class=\"alert alert-danger\">All field is <strong>required</strong>.</div>";
}
$query = $this->query("SELECT item FROM inventory WHERE item = '$item'");
if($query['num_rows'] > 0){
return "<div class=\"alert alert-danger\">The <strong>item</strong> already exist.</div>";
}
$query = $this->query("SELECT sku FROM inventory WHERE sku = '$sku'");
if($query['num_rows'] > 0){
return "<div class=\"alert alert-danger\">The <strong>Part# | SKU</strong> is already atribute to a other item.</div>";
}
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$this->query("UPDATE inventory SET (company, item, sku, glcode, qtyalert, qty, notes, image_name, image) VALUES ('$company', '$item', '$sku', '$glcode', '$qtyalert', '$qtyalert', '$notes', '{$image_name}', '{$image}') WHERE id='".$id."'");
return '<div class="alert alert-success">The item have been successfully <strong>updated</strong>.</div>';
}
}