The first section is from my updatecompany.php page, this is looking for the passed vars to update or display.
I keep getting errors that no ID is set, I can't for the life of me figure out where i went wrong. Any help would be great!
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.");
}
This is from my include with the function.
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;
}
}
Here are the errors.
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"
Here is the html form
<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>