Jump to content


Photo

For Each Insert Into Problem


  • Please log in to reply
4 replies to this topic

#1 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 28 August 2006 - 07:16 PM

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:

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;


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

$pathname = http://project.racka...JPGIMAG0006.JPG


thumbpath = http://project.racka...JPGIMAG0006.JPG


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

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 07:53 PM

$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>";
}



#3 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 28 August 2006 - 08:09 PM

ok that did change it but

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

http://project.racka...es/IMAG0006.JPG

it keeps combining them

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 08:38 PM

change:

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

to:

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

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

#5 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 28 August 2006 - 08:45 PM

ahhh yes,.. thanks man ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users