用户需要能够从图库中更新图像标题并更新数据库表-PHP SQL

时间:2019-03-17 15:25:23

标签: php html sql phpmyadmin

我的网页上有一个图片库,如果需要的话,我需要用户能够更新图片标题。我的代码如下所示(我尝试对SELECT查询使用准备好的语句,以确保它更安全。...但是,如果执行不正确,请说一下)。

我的画廊代码:

<?php
    if(isset($_POST['catID'])){
    $catID = $_POST['catID'];
    }

    if(isset($_POST['view-cat']))
    {
        $stmt = $conn->prepare ("SELECT * FROM `tblImage` WHERE `fldCatID` = ?");
        $stmt->bind_param("i", $catID);
        $stmt->execute();
        $result = $stmt->get_result();

        while($row = $result -> fetch_assoc())
            {
?>

<div class="item">
    <a href="<?php echo $row['fldFilePath']; ?>" data-lightbox="gallery" data-title="<?php echo $row['fldName']; ?>"><img alt src="<?php echo $row['fldFilePath']; ?>" class="ImgRound"></a>
</div>
<?php
            }
    } else {
        $query = "SELECT * FROM `tblImage` ";    
        $result = $conn->query($query);
        while($row = $result-> fetch_assoc())
            {
?>
<div class="item">
    <a href="<?php echo $row['fldFilePath']; ?>" data-lightbox="gallery" data-title="<?php echo $row['fldName']; ?>"><img alt src="<?php echo $row['fldFilePath']; ?>" class="ImgRound"></a>
</div>
<?php
            }
}
?>

Gallery

更新:对此进行了尝试,但出现错误:Undefined index: update-title-btn in

<button name="update-title-btn" type="submit" type="button">Update</button>


<?php
    if(isset($_POST['update-title-btn'])){
        $newTitle = $_POST['update-title-btn'];
        }
            $query= "UPDATE `tblImage` SET `fldName` = ? WHERE `fldFilePath` = ".$row['fldFilePath'];
            $stmt->bind_param("s", $newTitle);
            $stmt->execute();
            $result = $stmt->get_result();
?>

0 个答案:

没有答案