gpt4 book ai didi

php - 无法弄清楚php插入

转载 作者:行者123 更新时间:2023-11-28 23:21:16 26 4
gpt4 key购买 nike

<分区>

第一部分来 self 的 updatecompany.php 页面,它正在查找传递的变量以进行更新或显示。

我一直收到未设置 ID 的错误消息,我这辈子都弄不明白哪里出错了。任何帮助都会很棒!

if (isset($_POST["id"]) && is_numeric($_POST["id"])){
$id = $_POST["id"];
$vid = \Fr\LS::getCompany("id", $id);
$vname = \Fr\LS::getCompany("name", $id);
$vlogo = \Fr\LS::getCompany("logo", $id);
$vinfo = \Fr\LS::getCompany("info", $id);
$vsite = \Fr\LS::getCompany("site", $id);
$vest = \Fr\LS::getCompany("est", $id);
}elseif ( isset($_POST["update"]) ){
\Fr\LS::updateCompany(array(
"name" => $_POST["name"],
"logo" => $_POST["logo"],
"info" => $_POST["info"],
"site" => $_POST["site"],
"est" => $_POST["est"]),
$_POST["idnum"]);
echo "<center>Company updated!";
echo "<br><a href='updatecompany.php" . $_POST["idnum"] ."'>go back</a></center>";
}else {
die("No server with that id.");
}

这是我在函数中包含的内容。

public static function updateCompany($toUpdate = array(), $company = null){
self::construct();
if( is_array($toUpdate) && !isset($toUpdate['id']) ){
if($company == null){
echo "No company ID set!";
}
$columns = "";
foreach($toUpdate as $k => $v){
$columns .= "`$k` = :$k, ";
}

$sql = self::$dbh->prepare("UPDATE companys SET {$columns} WHERE `id` = :id");
$sql->bindValue(":id", $company);
foreach($toUpdate as $key => $value){
$value = htmlspecialchars($value);
$sql->bindValue(":$key", $value);
}
$sql->execute();

}else{
return false;
}
}

这是错误。

2017/01/06 16:39:19 [error] 9682#9682: *2752 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: logo in /xxx/xxx/xxxxxxxxxxx/master/updatecompany.php on line 17 PHP message: PHP Notice: Undefined index: idnum in /xxx/xxx/xxxxxxxxxxx/master/updatecompany.php on line 21 PHP message: PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = NULL' at line 1' in /xxx/xxx/xxxxxxxxxxx/inc/inc.php:917 Stack trace:

0 /xxx/xxx/xxxxxxxxxxx/inc/inc.php(917): PDOStatement->execute()

1 /xxx/xxx/xxxxxxxxxxx/master/updatecompany.php(21): Fr\LS::updateCompany(Array, NULL)

2 {main} thrown in /xxx/xxx/xxxxxxxxxxx/inc/inc.php on line 917" while reading response header from upstream, client: 75.189.195.82,

server: www.xxxxxxxx.com, request: "POST /master/updatecompany.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.xxxxxxxx.com", referrer: "http://www.xxxxxxxx.com/master/updatecompany.php"

这是html表单

<form action="updatecompany.php" method='POST'>
<div class="form-group">
<label for="ID">ID:</label>
<input name="idnum" type="" class="form-control" id="" value="<?php echo $vid; ?>" disabled>
</div>
<div class="form-group">
<label for="Name">Name:</label>
<input name="name" type="" class="form-control" id="name" value="<?php echo $vname; ?>">
</div>
<div class="form-group">
<label for="Logo">Logo:</label>
<input type="" class="form-control" id="logo" value="<?php echo $vlogo; ?>">
</div>
<div class="form-group">
<label for="Info">Info:</label>
<textarea name="info" class="form-control" rows="5" id="info"><?php echo $vinfo; ?></textarea>
</div>
<div class="form-group">
<label for="Site">Site:</label>
<input name="site" type="" class="form-control" id="site" value="<?php echo $vsite; ?>">
</div>
<div class="form-group">
<label for="EST">EST:</label>
<input name="est" type="" class="form-control" id="est" value="<?php echo $vest; ?>">
</div>
<button type="submit" value="update" name="update" id="update" class="btn btn-lg btn-primary">Save</button>
</form>

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