gpt4 book ai didi

PHP while 循环出错

转载 作者:行者123 更新时间:2023-11-30 23:32:06 25 4
gpt4 key购买 nike

好吧,我正在尝试制作一个简单的交易脚本,几周来我一直在努力寻找问题所在,现在我决定寻求帮助。我从数据库中选择了一些怪物以及交易信息,例如交易来自谁以及交易到谁。该脚本运行正常并说它已完成但不执行 2 次更新。从数据库中获取怪物然后更新所有者。我有 session 开始,页面顶部的数据库连接是为任何人说这是问题的

} else if ( $_POST['Submit'] == 'Complete' ) {

//// This is the bit which does the update and does not work

$TradeID = $_POST['id'];
$sql12 = mysql_query( "SELECT * FROM Trades WHERE ID='$TradeID'" );
$row12 = mysql_fetch_array( $sql12 ) or die( mysql_error() );

$unserialize11 = unserialize( $row12['MyPokemon'] );

foreach ( $unserialize11 as $poke222 ) {
$sql2 = mysql_query( "SELECT * FROM user_pokemon WHERE id='$poke222'" );
while ( $row2 = mysql_fetch_array( $sql2 ) ) {
$Update1 = mysql_query( "UPDATE user_pokemon SET belongsto='".$row12['Me']."' WHERE id='".$row2['ID']."'" );
}
}
$unserialize12 = unserialize( $row12['OtherPokemon'] );
foreach ( $unserialize12 as $poke122 ) {
$sql3 = mysql_query( "SELECT * FROM user_pokemon WHERE id='$poke122'" );
while ( $row3 = mysql_fetch_array( $sql3 ) ) {
$Update1 = mysql_query("UPDATE user_pokemon SET belongsto='".$row12['OtherPerson']."' WHERE id='".$row3['ID']."'" );
}
}

echo "You have successfully completed trade #".$TradeID."!";
}
} else if ($_GET['action'] == 'delete'){

我刚刚剪下了一些不起作用的代码,它很好地捕获了怪物,但只是没有进行更新我想也许我把 }} 放在了错误的地方或者可能有很多???

最佳答案

在清理您的格式后,您似乎有一个额外的分号,位于此处显示的 if 语句的末尾。在您的 if 语句中,您有 5 个 { 实例和 6 个 } 实例。删除最后一个 } 可能会解决您的问题。

保持您的代码良好的格式将减少将来的故障排除问题。我删除了此代码块的大部分内容以揭示问题所在:

if ( $_POST['Submit'] == 'Complete' ) {
/* Removed variable assignments */
/* Removed foreach & while */
/* Removed variable assignment */
/* Removed foreach & while */
/* Removed output */
}
} /* This brace shouldn't be here */

关于PHP while 循环出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10055501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com