To Loop or Not to Loop?
| From: | Jay Fitzgerald | Date: | Mon, 17 Nov 2003 19:43:09 +0000 |
| Subject: | To Loop or Not to Loop? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-169998@lists.php.net to get a copy of this message | ||
The code below inserts the same inventory item into the db multiple times - I just need 1 line entry for each inventory item, but multiple photos of each item....How to do this?
I know the code I wrote below is extremely awful, but I am a nebie and that was the only way I could get it to half-way do what I am wanting
<SNIP>
for($q=0;$q<$tot;$q++)
{
$thefile = $_FILES['userfile']['name'][$q];
$temp_name = $_FILES['userfile']['tmp_name'][$q];
$thefile1 = $_FILES['userfile']['name']['0'];
$thefile2 = $_FILES['userfile']['name']['1'];
$thefile3 = $_FILES['userfile']['name']['2'];
$thefile4 = $_FILES['userfile']['name']['3'];
$thefile5 = $_FILES['userfile']['name']['4'];
$thefile6 = $_FILES['userfile']['name']['5'];
$thefile7 = $_FILES['userfile']['name']['6'];
$thefile8 = $_FILES['userfile']['name']['7'];
if (move_uploaded_file($temp_name, $uploaddir.'/'.$thefile))
{
$connection = mysql_connect('localhost','*****','*****') or die ('Couldn\'t make connection.');
$db = mysql_select_db('*****', $connection) or die ('Couldn\'t select database.');
$sql = "INSERT INTO inventory (
id, status, stocknum, year, make, model, price, class, type, mileage, slides, extcolor, intcolor, awning, generator, bedsize, location, description, picname1, picname2, picname3, picname4, picname5, picname6, picname7, picname8
) VALUES (
'', '$_POST[status]', '$_POST[stocknum]', '$_POST[year]', '$_POST[make]', '$_POST[model]', '$_POST[price]', '$_POST[class]', '$_POST[type]', '$_POST[mileage]', '$_POST[slides]', '$_POST[extcolor]', '$_POST[intcolor]', '$_POST[awning]', '$_POST[generator]', '$_POST[bedsize]', '$_POST[location]', '$_POST[description]', '$thefile1', '$thefile2', '$thefile3', '$thefile4', '$thefile5', '$thefile6', '$thefile7', '$thefile8'
)";
$sql_result = mysql_query($sql) or die ('Couldn\'t execute query.');
if (!$sql_result)
{
echo 'Could not add inventory.<p>';
exit;
}
$invfile = "$thepath/$thefile";
}
else
{
$invfile = "$thepath/$spacer";
}
?>
<img src="<?= $invfile; ?>"><br />
<?php
}
$myid = mysql_insert_id();
mysql_close($connection);
</SNIP>
================================================
Jay Fitzgerald, Design Director
- Certified Professional Webmaster (CPW-A)
- Certified Professional Web Designer (CPWDS-A)
- Certified Professional Web Developer (CPWDV-A)
- Certified E-Commerce Manager (CECM-A)
- Certified Small Business Web Consultant (CWCSB-A)
Bayou Internet - http://www.bayou.com
Toll Free: 888.30.BAYOU (22968)
Vox: 318.338.2034 / Fax: 318.338.2506
E-Mail: jayfitz@bayou.com
ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf
================================================