gpt4 book ai didi

php - 使用数组插入mysql和php

转载 作者:行者123 更新时间:2023-11-29 04:26:07 26 4
gpt4 key购买 nike

我有下面的部分代码:

while($array = $result->fetch_assoc() ){


$second_query = "INSERT INTO".TBL_USERSDONTPAY."VALUES ($array[\"username\"], $array[\"password\"], '0',$array[\"userid|\"], )";

$second_result = $database->query($second_query);

}

查询似乎无效。有什么线索吗?我认为这是引号或其他问题。如何实际传递数组元素?

这是我的全部代码,我想将一行移动到另一张表

$q = "SELECT * FROM ".TBL_USERS." WHERE username = '$subuser'"; 
$result = $database->query($q);

if($result && $result->num_rows == 1){
while($array = $result->fetch_assoc() ){
$second_query = "INSERT INTO" . TBL_USERSDONTPAY . "VALUES ('" . $array['username'] . "', '" . $array['password'] . "', '0', '" . $array['userid'] ."')";


$second_result = $database->query($second_query);
if($second_result){
// it worked!
$q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'";
$database->query($q);
}
}
}

最佳答案

您需要清理该查询并删除最后的逗号。

$second_query = "INSERT INTO " . TBL_USERSDONTPAY . " VALUES ('" . $array['username'] . "', '" . $array['password'] . "', '0', '" . $array['userid'] . "')";

关于php - 使用数组插入mysql和php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11108119/

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