简体   繁体   中英

Updating a Specific Row in a mysql table

<?php
require_once 'config.php';
session_start();
$result = mysqli_query($link, "SELECT * FROM images where allowance=0 order by id desc");

while ($row = mysqli_fetch_array($result)) {
        ?>
            <div id='img_div'>
            <p><?php echo $row['image_text']; ?></p>
            <img src="images/<?php echo $row['image']; ?>" >
            <br><br>
            <a role="button" class="btn btn-outline-success app" name="publish" href='admin.php?publish=true'>Publish</a>&nbsp;
            <a role="button" class="btn btn-outline-danger app" name="reject"  href='admin.php?reject=true'>Reject</a>
            </div>

        <?php   
    }
    ?>
<?php
            if (isset($_GET['publish'])) {
                $test=$_GET['id'];
                $sql1 = "UPDATE images SET allowance='1' where id=$test"; 

                if (mysqli_query($link, $sql1)) {
                    echo "Record updated successfully";
                } else {
                    echo "Error updating record: " . mysqli_error($link);
                }
                }
                ?>  

What i am trying to do here is that i am admin. when users upload a photo, it will have allowance value as '0'.

click here to see my mysql table with allowance value as 0

It wont be shown in timeline. I will login through admin. So when i click publish, the allowance value is updated as 1 and thus it will be shown in timeline.

the problem here is that when i use this code all of the image gets updated as value 1.

click here to see my mysql table with allowance value as 0

I cannot find a specific WHERE condition for mysql command to update my allowance value..

or does anybody have any code for this concept.. ie, user uploads photo it will be stored in database and then after admin approves it it will be shown in timeline...

Thanks in advance...

<?php
require_once 'config.php';
session_start();
if (isset($_GET['publish'])) {
    $test=$_GET['id'];
    $sql1 = "UPDATE images SET allowance='1' where id=$test"; 

    if (mysqli_query($link, $sql1)) {
        echo "Record updated successfully";
    } else {
        echo "Error updating record: " . mysqli_error($link);
    }
}

$result = mysqli_query($link, "SELECT * FROM images where allowance=0 order by id desc");

while ($row = mysqli_fetch_array($result)) { ?>
    <div id='img_div'>
        <p><?php echo $row['image_text']; ?></p>
        <img src="images/<?php echo $row['image']; ?>" >
        <br><br>
        <a role="button" class="btn btn-outline-success app" name="publish" href='admin.php?publish=true&id=<?php echo $row['id']; ?>'>Publish</a>&nbsp;
        <a role="button" class="btn btn-outline-danger app" name="reject"  href='admin.php?reject=true'>Reject</a>
    </div>
<?php } ?>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM