<?php
session_start();
$user = $_SESSION['login'];
$mysql_connect = mysql_connect("localhost", "root", "");
$mysql_select_db = mysql_select_db("site");
$sql = "SELECT * FROM `msg_inbox` WHERE `to` = '$user'";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$mysql_connect = mysql_connect("localhost", "root", "");
$mysql_select_db = mysql_select_db("site");
$query = ("UPDATE msg_inbox SET unread = 0 WHERE id= ".$row['id']);
$result = mysql_query($query);
}
And I receive error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in on line 8
Can you help me?
You have reassigned
$resultin your loop. After the first iteration, the variable$resultwill hold a boolean indicating the success or failure of yourUPDATEstatement.Change:
To:
Or just:
And be careful of SQL injection holes.
EDIT actually, your whole code could and should be shortened to: