Forum Moderators: coopster
Column count doesn't match value count at row 1
My code is below, any ideas? Ultimatly I'd like to display the photo of each product on the "edit_product.php" page i wrote. Help!
<?php
# add_product.php
$page_title = 'Add A Product';
require_once ("includes/admin_header.inc"[smilestopper]);
require_once ("includes/config.inc"[smilestopper]);
function make_product_select_row ($which) {
global $db_connection;
echo '<tr><td align="right">Product ' . ucfirst ($which) . ':</td><td align="left"><select name="' . $which . '_id">
';
$tablename = 'product_' . $which . 's';
$columnname = 'product_' . $which . '_id';
$query = "select * from $tablename order by $columnname";
$db_query = mysql_query ($query, $db_connection) or die (mysql_error());
while ($row = mysql_fetch_array ($db_query)) {
echo "<option value=\"$row[0]\">$row[1]</option>\n";
}
echo '</select></td></tr>';
}
// Submit the query if the form has been submitted.
if ($HTTP_POST_VARS['submit']) {
$query = "insert into products values ('0', '$HTTP_POST_VARS[name_id]', '$HTTP_POST_VARS[size_id]', '$HTTP_POST_VARS[format_id]', '$HTTP_POST_VARS[price]', '$HTTP_POST_VARS[sku]', '$HTTP_POST_VARS[picture]', '')";
mysql_query ($query, $db_connection) or die (mysql_error());
}
echo '</table>
<br />
<table>
<tr><td align="left"><u>Add a new product:</u><br><br></td></tr>
<form action="add_product.php" method="post">
';
make_product_select_row ('name');
make_product_select_row ('size');
make_product_select_row ('format');
echo '
<tr><td align="right">Price Per Unit:</td><td align="left"><input type="text" name="price" size="10"></td></tr>
<tr><td align="right">Item ID:</td><td align="left"><input type="text" name="sku" size="10"></td></tr>
<tr><td align="right">Image:</td><td align="left"><input type="text" name="picture" size="20"></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="submit" value="Add Product"></td></tr>
</form>
</table>';
require_once ("includes/admin_footer.inc"[smilestopper]);
?>
that would give you such error.
Since you are trying to create a tuple with 4 columns in a table that only has 3.
It is your INSERT statement you are building in your $query variable; as bcc1234 stated, that means you are trying to insert more values than there are columns in your table.
>> My mytable do you mean a database table or an html table?
Database table.
>> Is there an easier way to use images in my cart with this code? I tried adding it as just another textbox on the
>> add_product.php page and figured once I had a url for an
>> image in the db I could get it to echo in an img src tage somehow...
You could, as long as the image has been uploaded into the directory/folder that was entered into the textbox. It doesn't do any good to tell the server to load an image if the actual image doesn't exist.
Is there an easier way to use images in my cart with this code?
Easier for whom? I mean do you want to make it easier to code or easier to use?
I did a mod that added multiple image functionality to OSCommerce and it was rather complicated, but I think it was easy for the end user. Basically, I used a file upload input box (rather than a text box) and then just used the filename for the entry in the database (with all sorts of checking to make sure the pathname was valid and didn't delete anything of importance).
I also had a lot of other stuff (multiple views of a product, multiple sizes for each view, dynamic renaming if a file of that name already existed in the shop, custom paths and directory structure based on product, brand, category... maybe a little too complicated, but darn flexible), but basically the idea was to avoid having the user type anything in so that a typo would not result in broken images.