這是我的DB:當我更新時,我得到一個成功的消息,但沒有任何變化。我做錯了什麼?
表:Terras_Sico
列---------------類型--------------空
id ---------------------- int(11)-----------沒有
nome ------ ----------- varchar(250)---否
preco_publico -------十進制(10,2) - 否
imagem --------- ------ varchar(250) - 否
nota_prova ----------- varchar(250) - 否
produtor_enologo --- varchar(250) - 否
ano --------------------- varchar(250) - 否
tipo ------------- --------- VARCHAR(250)
這是我的代碼:
<?php
\t ini_set('display_errors', true);
\t error_reporting(E_ALL);
\t
\t error_reporting(~E_NOTICE);
\t
\t require_once 'dbconfig.php';
\t
\t if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
\t {
\t \t $id = $_GET['edit_id'];
\t \t $stmt_edit = $DB_con->prepare('SELECT nome, preco_publico, imagem, nota_prova, produtor_enologo, ano, tipo FROM Terras_Sico WHERE id =:uid');
\t \t $stmt_edit->execute(array(':uid'=>$id));
\t \t $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
\t \t extract($edit_row);
\t }
\t else
\t {
\t \t header("Location: index.php");
\t }
\t
\t
\t
\t if(isset($_POST['btn_save_updates']))
\t {
\t \t $nome = utf8_decode($_POST[nome]);
\t \t $preco_publico = utf8_decode($_POST[preco_publico]);
\t \t $nota_prova = utf8_decode($_POST[nota_prova]);
\t \t $produtor_enologo = utf8_decode($_POST[produtor_enologo]);
\t \t $ano = utf8_decode($_POST[ano]);
\t \t $tipo = utf8_decode($_POST[tipo]);
\t \t \t
\t \t $imgFile = $_FILES['u_imagem']['name'];
\t \t $tmp_dir = $_FILES['u_imagem']['tmp_name'];
\t \t $imgSize = $_FILES['u_imagem']['size'];
\t \t \t \t \t
\t \t if($imgFile)
\t \t {
\t \t \t $upload_dir = '../../../../d.sesnando/'; // upload directory \t
\t \t \t $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
\t \t \t $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
\t \t \t $userpic = rand(1000,1000000).".".$imgExt;
\t \t \t if(in_array($imgExt, $valid_extensions))
\t \t \t { \t \t \t
\t \t \t \t if($imgSize < 5000000)
\t \t \t \t {
\t \t \t \t \t unlink($upload_dir.$edit_row['imagem']);
\t \t \t \t \t move_uploaded_file($tmp_dir,$upload_dir.$userpic);
\t \t \t \t }
\t \t \t \t else
\t \t \t \t {
\t \t \t \t \t $errMSG = "Sorry, your file is too large it should be less then 5MB";
\t \t \t \t }
\t \t \t }
\t \t \t else
\t \t \t {
\t \t \t \t $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; \t \t
\t \t \t } \t
\t \t }
\t \t else
\t \t {
\t \t \t // if no image selected the old image remain as it is.
\t \t \t $userpic = $edit_row['imagem']; // old image from database
\t \t } \t
\t \t \t \t \t \t
\t \t
\t \t // if no error occured, continue ....
\t \t if(!isset($errMSG))
\t \t {
\t \t \t $stmt = $DB_con->prepare('UPDATE Terras_Sico
\t \t \t \t \t \t \t \t \t SET nome=:unome,
\t \t \t \t \t \t \t \t \t \t preco_publico=:upreco_publico,
\t \t \t \t \t \t \t \t \t \t imagem=:uimagem,
\t \t \t \t \t \t \t \t \t \t \t nota_prova=:unota_prova,
\t \t \t \t \t \t \t \t \t \t produtor_enologo=:uprodutor_enologo,
\t \t \t \t \t \t \t \t \t \t ano=:uano,
\t \t \t \t \t \t \t \t \t \t \t tipo=:utipo
\t \t \t \t \t \t \t \t WHERE id=:uid');
\t \t \t $stmt->bindParam(':unome',$nome);
\t \t \t $stmt->bindParam(':upreco_publico',$preco_publico);
\t \t \t $stmt->bindParam(':uimagem',$imagem);
\t \t \t $stmt->bindParam(':unota_prova',$nota_prova);
\t \t \t $stmt->bindParam(':uprodutor_enolog',$produtor_enologo);
\t \t \t $stmt->bindParam(':uano',$ano);
\t \t \t $stmt->bindParam(':utipo',$tipo);
\t \t \t $stmt->bindParam(':uid',$id);
\t \t \t \t
\t \t \t if($stmt->execute()){
\t \t \t \t ?>
<script>
\t \t \t \t alert('Successfully Updated ...');
\t \t \t \t window.location.href='index.php';
\t \t \t \t </script>
<?php
\t \t \t }
\t \t \t else{
\t \t \t \t $errMSG = "Sorry Data Could Not Updated !";
\t \t \t }
\t \t
\t \t }
\t \t
\t \t \t \t \t \t
\t }
\t
?>
<!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>Upload, Insert, Update, Delete an Image using PHP MySQL - Coding Cage</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="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="../../insercao/panel.php" title='Programming Blog'>Inicio</a>
<a class="navbar-brand" href="index.php">Voltar</a>
</div>
</div>
</div>
<div class="container">
\t <div class="page-header">
\t <h1 class="h2">Update Produto <a class="btn btn-default" href="index.php"> Todos os produtos </a></h1>
</div>
<div class="clearfix"></div>
<form method="post" enctype="multipart/form-data" class="form-horizontal">
\t
<?php
\t if(isset($errMSG)){
\t \t ?>
<div class="alert alert-danger">
<span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
</div>
<?php
\t }
\t ?>
\t <table class="table table-bordered table-responsive">
\t
<tr>
\t <td><label class="control-label">Nome</label></td>
<td><input class="form-control" type="text" name="nome" value="<?php echo $nome; ?>" required /></td>
</tr>
<tr>
\t <td><label class="control-label">Preço ao Público</label></td>
<td><input class="form-control" type="text" name="preco_publico" value="<?php echo $preco_publico; ?>" required /></td>
</tr>
<tr>
\t <td><label class="control-label">Nota de Prova</label></td>
<td><input class="form-control" type="text" name="nota_prova" value="<?php echo $nota_prova; ?>" required /></td>
</tr>
<tr>
\t <td><label class="control-label">Produtor/Énologo</label></td>
<td><input class="form-control" type="text" name="produtor_enologo" value="<?php echo $produtor_enologo; ?>" required /></td>
</tr>
<tr>
\t <td><label class="control-label">Ano</label></td>
<td><input class="form-control" type="text" name="ano" value="<?php echo $ano; ?>" required /></td>
</tr>
<tr>
\t <td><label class="control-label">Tipo</label></td>
<td><input class="form-control" type="text" name="tipo" value="<?php echo $tipo; ?>" required /></td>
</tr>
<tr>
\t <td><label class="control-label">Imagem</label></td>
<td>
\t <p><img src="../../../../d.sesnando/<?php echo $imagem; ?>" height="150" width="150" /></p>
\t <input class="input-group" type="file" name="imagem" 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="index.php"> <span class="glyphicon glyphicon-backward"></span> cancelar </a>
</td>
</tr>
</table>
</form>
<div class="alert alert-info">
<strong>tutorial link !</strong> <a href="http://www.codingcage.com/2016/02/upload-insert-update-delete-image-using.html">Coding Cage</a>!
</div>
</div>
</body>
</html>
有了這樣_問題: 「爲什麼沒有這個代碼工作_/_?」 爲什麼我得到這個錯誤「_很難爲在這種情況下,你應該包括所需的行爲,如果可能的話,包括一個[最小,完整和可驗證的例子](http://stackoverflow.com/help/mcve) – lealceldeiro
對不起,我 所以我需要幫助,因爲我的更新說明了它,但它不會改變任何東西。我是否必須創建一個新帖子,或者它可以在這個嗎? –
當然,你可以編輯自己的帖子。您無需發表其他問題。 – lealceldeiro