Mysql在缺少html图像时创建双重插入

I have found an error in my code that somehow having html code with a image with no url causes my mysql query to insert twice. Is there any logic to this or is there something else wrong in my code? Please keep in mind hat I am still learning php and mysql.

HTML code

<td width="70"><img src="" height="70" width="70"></td>

MYSQL code

mysql_query("INSERT INTO `database`.`user_inventory` (`user_id`, `item_id`, `status`) VALUES (1, 1, 'locked')");

An image with no src tries to load the current page as the image (the same way how <a href=""> links back to the current page). If the MySQL query is triggered every time the page is loaded that's why you're seeng it happen twice. There's not really a reason to have an empty src anyway.

When you leave off the src attribute or do not specify it (src="") your browser will default the value to the current page sending a second request. This would likely be the source of your secondary insert.