Reputation: 1
This is my first time on SO, so I'm not knowing about everything. I'm sorry. I have a problem with my site. I want to update the viewed status of one of the rows.
This is my update code:
<?php
if(isset($_POST['Submit'])){//if the submit button is clicked
$sql= mysql_query ("UPDATE system_reports SET viewed=1 WHERE id =' ".$row['id']." ' ");
$conn->query($sql) or die("Cannot update");//update or error
}
?>
But when I click on the button, I get: Cannot Update
. The connection of DB is fine. So I don't know what is the problem. ID is a realy working variable.
So is my rows working:
<?php
function spam_Draw() {
$a = mysql_query("SELECT * FROM system_reports WHERE viewed=0");
while ($row = mysql_fetch_array($a)) {
echo $row['id']." <a href='http://warrock-hack.net/profiel/".$row['user'] . "/'>Gedupeerde</a> <a href='" . $row['report_url'] . "'> Ga naar het probleem toe!</a> " . $row['reason'];
echo '<br>';
echo '<INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"> ';
}
}
?>
I hope someone can help me out! Thanks..
Regards,
John.
Upvotes: 0
Views: 64
Reputation: 360562
Your DB calls are totally wrong. mysql_query()
returns a query handle representing the results of your query (or boolean false on failure). You're taking that handle, and feeding it to some OTHER database library.
mysql
, mysqli
and PDO
database handles/results are NOT interchangeable, and the libraries cannot be mixed together like that.
You probably want something more like:
$sql = "UPDATE.... " . $row['id']; // no mysql_query() call, just defining a string
$result = $conn->query($sql);
Plus, die()ing with a fixed string for your error message is utterly useless. The DB libraries can TELL you what the problem was:
$result = $conn->query($sql) or die(mysqli_error()); // assuming mysqli
Upvotes: 2