knowledge
-
Posts
2 -
Joined
-
Last visited
-
Days Won
1
Posts posted by knowledge
-
-
After trying to add a product to the DB, I get an error saying there is an undefined variable (ext) in the add products script. Below is the lines where it is used:
$new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext);
Here is the whole IF statement:
if (!array_key_exists('image', $add_product_errors)) {$new_name = sha1($file['name'] . uniqid('',true));$new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext);$dest = "../products/$new_name";if (move_uploaded_file($file['tmp_name'], $dest)) {$_SESSION['image']['new_name'] = $new_name;$_SESSION['image']['file_name'] = $file['name'];echo '<h4>The file has been uploaded!</h4>';} else {trigger_error('The file could not be moved.');unlink ($file['tmp_name']);}}My question is should this be declared as empty? Basically declaring it like this:if (!array_key_exists('image', $add_product_errors)) {$ext = ' ';$new_name = sha1($file['name'] . uniqid('',true));$new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext);$dest = "../products/$new_name";if (move_uploaded_file($file['tmp_name'], $dest)) {$_SESSION['image']['new_name'] = $new_name;$_SESSION['image']['file_name'] = $file['name'];echo '<h4>The file has been uploaded!</h4>';} else {trigger_error('The file could not be moved.');unlink ($file['tmp_name']);}}
Undefined Variable In Add_Other_Products.php Script "ext"
in Effortless E-Commerce with PHP and MySQL (2nd Edition)
Posted
Found the error!
You defined the extension with $file_ext like so: