第一部分是从我的updatecompany.php页面,这是寻找通过的vars更新或显示。
我不断地收到错误,没有设置任何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错误9682#9682:*2752 FastCGI在stderr中发送:"PHP消息:未定义索引: /xxx/xxx/xxxxxxxxxxx/master/updatecompany.php中的徽标,在第17行PHP消息中: PHP通知:未定义索引: idnum in /xxx/xxx/xxxxxxxxxxx/master/updatecompany.php在第21行PHP消息: PHP致命错误:带有消息'SQLSTATE42000:语法错误或访问违规: 1064您的SQL语法中有一个错误;检查与您的MySQL服务器版本对应的手册,以获得在/xxx/xxx/xxxxxxxxxxx/inc/inc.php:917堆栈跟踪的第1行附近使用“WHERE
id=NULL”的正确语法: 0 /xxx/xxx/xxxxxxxxxxx/inc/inc.php(917):PDOStatement->execute() 1 /xxx/xxx/xxxxxxxxxxx/master/updatecompany.php(21):Fr\LS::updateCompany(数组,NULL) 2 {main}在第917行中抛入/xxx/xxx/xxxxxxxxxxx/inc/inc.php,同时从上游读取响应头,客户端: 75.189.195.82, 服务器: www.xxxxxxxx.com,请求:"POST /master/updatecompany.php HTTP/1.1",上游:“referrer: //unix:/var/run/php5-fpm.sock:”,主机:"www.xxxxxxxx.com",引用者:"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>发布于 2017-01-06 21:09:22
乍一看,这似乎是
$columns = ""; foreach($toUpdate as $k => $v){ $columns .= "$k= :$k, "; }
正在产生这样的东西
name= :name,foo= :foo,
结尾处的后缀逗号将生成错误的SQL。
https://stackoverflow.com/questions/41514048
复制相似问题