From 63008cb4dea2a7253916707fb0dce1be1cfaf810 Mon Sep 17 00:00:00 2001 From: Ryan Walberg Date: Mon, 6 May 2024 21:34:32 -0400 Subject: [PATCH 1/2] fix undefined variable warning; tune up .gitignore --- .gitignore | 3 +++ src/item.php | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6bfc4ca --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +src/templates_c +src/item_images + diff --git a/src/item.php b/src/item.php index 193fa5e..479ad9f 100644 --- a/src/item.php +++ b/src/item.php @@ -181,8 +181,13 @@ if (!empty($_REQUEST["action"])) { } else if ($action == "insert") { if (!$haserror) { - $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}items(userid,description,price,source,category,url,ranking,comment,quantity" . ($image_base_filename != "" ? ",image_filename" : "") . ") " . - "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?" . ($image_base_filename != "" ? ", ?)" : ")")); + if (isset($image_base_filename) && $image_base_filename != "") { + $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}items(userid,description,price,source,category,url,ranking,comment,quantity,image_filename) " . + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + } else { + $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}items(userid,description,price,source,category,url,ranking,comment,quantity) " . + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"); + } $stmt->bindParam(1, $userid, PDO::PARAM_INT); $stmt->bindParam(2, $description, PDO::PARAM_STR); $stmt->bindParam(3, $price); @@ -192,7 +197,7 @@ if (!empty($_REQUEST["action"])) { $stmt->bindParam(7, $ranking, PDO::PARAM_INT); $stmt->bindParam(8, $comment, PDO::PARAM_STR); $stmt->bindParam(9, $quantity, PDO::PARAM_INT); - if ($image_base_filename != "") { + if (isset($image_base_filename) && $image_base_filename != "") { $stmt->bindParam(10, $image_base_filename, PDO::PARAM_STR); } $stmt->execute(); From db7e1f08a9cde91d3c2a47d2f5c4120b31b24c71 Mon Sep 17 00:00:00 2001 From: Ryan Walberg Date: Fri, 10 May 2024 18:02:29 -0400 Subject: [PATCH 2/2] cleaner way to do that --- src/item.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/item.php b/src/item.php index 479ad9f..d5964b3 100644 --- a/src/item.php +++ b/src/item.php @@ -181,13 +181,8 @@ if (!empty($_REQUEST["action"])) { } else if ($action == "insert") { if (!$haserror) { - if (isset($image_base_filename) && $image_base_filename != "") { - $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}items(userid,description,price,source,category,url,ranking,comment,quantity,image_filename) " . - "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); - } else { - $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}items(userid,description,price,source,category,url,ranking,comment,quantity) " . - "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"); - } + $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}items(userid,description,price,source,category,url,ranking,comment,quantity,image_filename) " . + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bindParam(1, $userid, PDO::PARAM_INT); $stmt->bindParam(2, $description, PDO::PARAM_STR); $stmt->bindParam(3, $price); @@ -197,9 +192,10 @@ if (!empty($_REQUEST["action"])) { $stmt->bindParam(7, $ranking, PDO::PARAM_INT); $stmt->bindParam(8, $comment, PDO::PARAM_STR); $stmt->bindParam(9, $quantity, PDO::PARAM_INT); - if (isset($image_base_filename) && $image_base_filename != "") { - $stmt->bindParam(10, $image_base_filename, PDO::PARAM_STR); - } + if (!isset($image_base_filename) || $image_base_filename == "") { + $image_base_filename = NULL; + } + $stmt->bindParam(10, $image_base_filename, PDO::PARAM_STR); $stmt->execute(); stampUser($userid, $smarty->dbh(), $smarty->opt());