Jump to content

Archived

This topic is now archived and is closed to further replies.

piznac

For Each Insert Into Problem

Recommended Posts

I have a long script that I have asked questions about in another post. I have everything working except the last portion. I have a form with 10 file fields,.. I have called these as an array. When I try to put the path name in the database I get some wierd results. Please let me know what Im doing wrong:

[quote]foreach ($_FILES['file']['name'] as $value3) {


$pathname .= "$path$value3";
$thumbpath .= "$path2$value3";
$mysql = "rack_pm";
mysql_select_db($mysql);
$sql = "INSERT INTO `returnedfiles` (`imagepath`, `thumbpath`, `jobnum`, `pname`, `num`, `autojobnum`) VALUES ('$pathname', '$thumbpath', '000', 'nada', NULL, '1');";

mysql_query($sql) or die('Error, insert query failed');

}
echo $pathname;
echo $thumbpath;[/quote]

the results Im getting with the database and the echo are:

[quote]$pathname = http://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGIMAG0006.JPG


thumbpath = http://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/thumbs/IMAG0011.JPGIMAG0006.JPG[/quote]

as you can see Im getting tons of records I dont need,.. any help would be great
At this point only two fo the ten file fields have been used,.. so I should only get two results

Share this post


Link to post
Share on other sites
[code]$mysql = "rack_pm";
mysql_select_db($mysql);

foreach ($_FILES as $value) {
$pathname .= $path . $value['name'];
$thumbpath .= $path2 . $value['name'];
$sql = "INSERT INTO `returnedfiles` (`imagepath`, `thumbpath`, `jobnum`, `pname`, `num`, `autojobnum`) VALUES ('$pathname', '$thumbpath', '000', 'nada', NULL, '1')";
mysql_query($sql) or die(mysql_error());
echo $pathname . "<br>";
echo $thumbpath . "<br><br>";
}

[/code]

Share this post


Link to post
Share on other sites
ok that did change it but

the first entry was right,.. but the 2nd returned this:

http://project.rackattackzone.com/jobs/Nike/return_images/IMAG0011.JPGhttp://project.rackattackzone.com/jobs/Nike/return_images/IMAG0006.JPG

it keeps combining them

Share this post


Link to post
Share on other sites
change:

[code]$pathname .= $path . $value['name'];
$thumbpath .= $path2 . $value['name'];[/code]

to:

[code]$pathname = $path . $value['name'];
$thumbpath = $path2 . $value['name'];[/code]

Notice it's no longer using the ".=" (concatenation) operator.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.