gpt4 book ai didi

php - 更新查询有效但不插入查询

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

我在将信息插入数据库时​​遇到问题。奇怪的是,更新查询有效但插入查询无效。提交时我也没有收到任何错误,它正确通过并保存了 echo 帐户,但没有插入任何内容。我错过了什么或做错了什么。请协助

if(isset($_POST['Submitaccount'])){
$allowedusers = $_POST['users'];
$accountid = trim($_POST['accountid']);
if(!$_POST['copyperms']) $_POST['copyperms']='N';
if(!$_POST['allusers']) $_POST['allusers']='N';
if(!$_POST['enabled']) $_POST['enabled']='N';
if(!$_POST['servertime']) $_POST['servertime']='N';
if(!$_POST['delremovals']) $_POST['delremovals']='N';

unset($_POST['Submitaccount']);
unset($_POST['accountid']);
unset($_POST['users']);

$notmust = array("email" , "skip" , "comments" , "firstmod");

foreach($_POST as $key=>$val){
if(!trim($val) && !in_array($key , $notmust)) {
$err = 1;
$empty = "$key";
break;
}
$qpart .= "`$key` = '".mysql_escape_string($val)."' , " ;
}
if($qpart) $qpart = substr($qpart , 0 , -2);

if(!$err){
$chk = mysql_num_rows(mysql_query("SELECT * from accounts WHERE name = '".mysql_escape_string($_POST['name'])."' and id <> '$accountid'"));
if($chk >0){
$err = 2;
}
}

if(!$err){
if(!$accountid){
$q = "INSERT into accounts SET $qpart ";
mysql_query($q) or die("Error inserting the record :".mysql_error()."<br>".$q);
$accountid = mysql_insert_id();
}else{
$q = "UPDATE accounts SET $qpart WHERE id = '$accountid'";
mysql_query($q) or die("Error updating the record :".mysql_error()."<br>".$q);
}
}

最佳答案

这是因为 INSERT 命令有不同的语法:

INSERT into accounts SET $qpart "

不常见,可以这样写:

INSERT into accounts (column names) VALUES your values"

13.2.5 INSERT Syntax

关于php - 更新查询有效但不插入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28104372/

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