我试图更新我的数据库中的第一行。我使用Limit 1
只更新第一行,但没有任何事情发生。绝对有匹配的行,但数据库中没有任何更改。更新第一行mysql php
下面是代码:
foreach ($player_fromsite as $match_player_in_game) {
//$querytwo = 'INSERT INTO `'.$tablename.'` '.' (`'.$match_player_in_game.'`) '.'VALUES'.'("' . 'yes' . '")';
$querytwo = 'UPDATE '.$tablename.' SET `'.$match_player_in_game.'` = "'.'yes'.'" WHERE `'.$match_player_in_game.'` = "'.'NULL'.'" LIMIT 1';
$querythree = 'UPDATE '.$tablename.' SET `'.$match_player_in_game.'` = "'.'yes'.'" WHERE `'.$match_player_in_game.'` = "'.'NULL'.'" LIMIT 1';
for($a=0;$a<11;$a++){
if($match_player_in_game == $home_players[$a]){
// Insert a row of information into the table "example"
mysql_query($querytwo) or die(mysql_error());
}else{
mysql_query($querythree) or die(mysql_error());
}
}
}
是查询是否正确?
你能发布一个生成的SQL样本,而不是你的PHP代码吗? –
请不要**在新应用程序中使用mysql_query,如果您在这里使用不正确,它将被弃用,并且会从未来版本的PHP中删除。像[PDO这样的现代化替代品并不难学](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/)。像[PHP正确的方式](http://www.phptherightway.com/)这样的指南将帮助您避免出现这样的错误。 **总是** [妥善转义](http://bobby-tables.com/php)任何和所有的值,以避免严重的[SQL注入漏洞](http://bobby-tables.com/)。 – tadman
感谢那 – Procode