Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<div id="main">

            <?php
if (isset($_GET['id']))
{
    $i = $_GET['id'];
}
else {
    $i = "";
}
            $sql = "UPDATE tblconcerns SET read_status=1 WHERE message_id = $i";


            $sql = "SELECT * FROM tblconcerns WHERE message_id = $i";
            $result = mysqli_query($conn, $sql);
            ?>
            <div style="text-align: left; margin-bottom: 20px">

                <strong>Subject: </strong>

            <?php
            if ($result)
            {
                echo $sql;
                while ($row = mysqli_fetch_array($result))
                {


                    echo $row['title']."<br/>"
                            . "<strong>Sender's email:</strong> ".$row['sender_email']."<br/>"
                            . "<strong>Date/Time:</strong> ".$row['date']."/".$row['time']
                            ."READ: {$row['read_status']}"
                            . "<hr>";
                    ?>
            </div>
            <div style="text-align: center">
            <?php
            echo $row['concern'];

                }
                ?>
            </div>
                <?php
            }

            else {
                echo mysqli_error();
            }


            ?>
        </div>


I tried my update query in phpmyadmin and it works just fine, however when I'm trying to see if it works in the actual site, it doesn't update. I'm using the user 'root' which has all the privileges enabled.
Posted
Updated 2-Oct-15 4:37am
v4
Comments
Richard Deeming 2-Oct-15 11:02am    
You seem to be missing the code to execute the UPDATE query. You've assigned the query to a string, and then immediately overwritten it.
kmllev 2-Oct-15 11:07am    
What code could that possibly be? I tried to separate the query for update in a separate php file and then just set a header to redirect to the php file that will display things, but it's still not working?

1 solution

You're missing the code to execute the UPDATE query.

Something like this should work:
PHP
if (isset($_GET['id']))
{
    $i = $_GET['id'];
    $sql = "UPDATE tblconcerns SET read_status=1 WHERE message_id = $i";
    mysqli_query($conn, $sql);
}

$sql = "SELECT * FROM tblconcerns WHERE message_id = $i";
$result = mysqli_query($conn, $sql);

However, this code is vulnerable to SQL Injection[^]. You need to use preparent statements[^] to pass the parameter to the query.
PHP
if (isset($_GET['id']))
{
    if ($stmt = mysqli_prepare($conn, "UPDATE tblconcerns SET read_status = 1 WHERE message_id = ?")) 
    {
        $id = $_GET['id'];
        mysqli_stmt_bind_param($stmt, "id", $id);
        mysqli_stmt_execute($stmt);
    }
}
 
Share this answer
 
Comments
kmllev 2-Oct-15 11:26am    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900