2016-08-03 3 views
1

データベースのデータを簡単に編集/更新しようとしています。しかし何とかそれは動作しません。PHP/MySqlで動作しないデータの簡単な更新/編集

保存されたデータをフォームに読み込むことができます。また、私は自分のコードを見つめていたし、時間のグーグルが、私は私のコードでミスを犯したかもしれないところ、私は表示されませんしたエラー

enter image description here

を持っていません。

印刷エコーが右のようだ次のような出力が得られます。

enter image description here

HTMLコード:/更新を編集するために私のPHPコードの

<form id="formAddCategory" class="FrmCat" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    <div class="form-group"> 
     <!-- hidden id from tbl --> 
     <input type="hidden" name="hiddenId" value="<?php echo $hiddenID ?>" /> 
     <label for="recipient-name" class="control-label">Category Name:</label> 
     <input type="text" class="form-control" id="recipient-name1" name="category" required="" value="<?php echo $category ?>" /> 
    </div> 
    <button type="submit" id="btnEditCat" class="btn btn-danger" name="editCategory">Save Category</button> 
</form> 

パート:

<?php 
//edit/update data to db 
if(isset($_POST['editCategory'])){ 
    $categoryUpdate = mysqli_real_escape_string($con, $_POST['category']); 
    $categoryID = mysqli_real_escape_string($con, $_POST['hiddenId']); 
    $qry = "UPDATE tbl_Category SET category = $categoryUpdate WHERE category_id = $categoryID"; 
    $result = mysqli_query($con, $qry); 
    echo $qry; 

    if($result){ 
    header("Location: category.php"); 
    } 
} 

?> 

答えて

1

また、あなたはSQLインジェクション(See here)を避けるために、このように使用できる値

$qry = "UPDATE tbl_Category SET category = '$categoryUpdate' WHERE category_id = '$categoryID'"; 

ための単一引用符(')を使用する必要があります

$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?'); 
$stmt->bind_param('s', $name); 

$stmt->execute(); 

$result = $stmt->get_result(); 
while ($row = $result->fetch_assoc()) { 
    // do something with $row 
} 
2

一重引用符が必要'をラップするあなたのパラメータ:

$qry = "UPDATE tbl_Category SET category = '$categoryUpdate' WHERE category_id = '$categoryID'"; 
+0

、このような愚かなOMG間違いと私は私のコードで何時間も見つめている。ありがとう – GY22

関連する問題