Hey all,
Hoping someone can help me - I'm getting the following error:
Notice: Undefined index: category_name in F:\xampp\htdocs\458558_class\cms_class.php on line 63
And well, I'm not sure why. It's just the category name that doesn't seem to work - all of the others do (product_price, product_stock etc) and I can't see anything in the code happening to those variables that isn't happening to category_name.
I apologise for the lengthy code.
function add_product($p) {
$product_name = mysql_real_escape_string($p['product_name']);
$category_name = mysql_real_escape_string($p['category_name']);
$product_price = mysql_real_escape_string($p['product_price']);
$product_stock = mysql_real_escape_string($p['product_stock']);
$product_desc = mysql_real_escape_string($p['product_desc']);
if(!$product_name || !$category_name || !$product_price || !$product_stock || !$product_desc):
if(!$product_name):
echo "<p>A product name is required.</p>";
endif;
if(!$product_price):
echo "<p>A product price is required.</p>";
endif;
if(!$category_name):
echo "<p>A product category is required.</p>";
endif;
if(!$product_stock):
echo "<p>A product stock is required.</p>";
endif;
if(!$product_desc):
echo "<p>A product description is required.</p>";
endif;
echo '<p><a href="add_product.php">Please try again.</p></a>';
else:
$sql = "INSERT INTO product VALUES (null, '$product_name', '$category_name' '$product_price', '$product_stock', '$product_desc')";
$result = mysql_query($sql) or die(mysql_error());
echo "Product added successfully.";
endif;
}
And the following is the code for the HTML forms for input.
<input type="hidden" name="add" id="add" value="true" />
<div>
<label for="product_name">Product name:</label>
<input type="text" name="product_name" id="product_name" />
</div>
<div>
<label for="category_name">Product category:</label>
<select name="category_name" id="category_name" />
<option>BLU RAY</option>
<option>CD</option>
<option>DVD</option>
<option>PC</option>
<option>PS3</option>
<option>WII</option>
<option>XBOX 360</option>
</select>
</div>
<div>
<label for="product_image">Product image:</label>
<input type="file" name="product_image" id="product_image" accept="image/jpeg">
</div>
<div>
<label for="product_price">Product price:</label>
<input type="text" name="product_price" id="product_price">
</div>
<div>
<label for="product_stock">Product stock:</label>
<input type="text" name="product_stock" id="product_stock">
</div>
<div>
<label for="product_desc">Product description:</label>
<textarea placeholder="Maximum 1000 characters." name="product_desc" id="product_desc" rows="10" cols="50"></textarea>
</div>
<input type="submit" name="submit" value="Add Product" />
<input type="reset" name="reset" value="Reset" />
</form>
</div>
Any help would be appreciated.