php-general Digest 1 May 2010 05:54:11 -0000 Issue 6721
Topics (messages 304787 through 304801):
Re: How to Force IE to download text file?
304787 by: Michael Shadle
Re: Two color rows in table inside while iteration
304788 by: tedd
304789 by: tedd
304790 by: Ashley Sheridan
304791 by: tedd
304793 by: Ashley Sheridan
Re: Two color rows in table inside while iteration -- just say no to mod
304792 by: Daevid Vincent
304795 by: Jason Pruim
multi dimensional array question
304794 by: Nick Balestra
304796 by: Piero Steinger
304797 by: Nick Balestra
Any One See where this is going wrong?
304798 by: Gary
304799 by: Ashley Sheridan
304800 by: Gary
304801 by: kranthi
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On Fri, Apr 30, 2010 at 9:19 AM, Ali Asghar Toraby Parizy
<aliasghar.tor...@gmail.com> wrote:
> I have written this code to export data to a text file and asks user
> to save generated file. It works with Firefox perfectly, but IE shows
> content of file instead of prompting the download window.
> How can I force IE to show the download dialog?
>
> <?php
> Header("Content-disposition: attachement; filename=data.txt");
> Header("Content-type: text/plain");
> echo $some_data;
> ?>
We usually do something like this. Although I am not sure about text files.
header("Content-Disposition: attachment;
filename=\"".urldecode(basename($file))."\";");
header("Content-Type: application/force-download");
--- End Message ---
--- Begin Message ---
At 10:34 AM -0400 4/30/10, Paul M Foster wrote:
On Thu, Apr 29, 2010 at 05:34:38PM -0400, tedd wrote:
> Please critically review my example.
+1
This thread came up before, and tedd's solution was the least complex,
as far as I could tell. I shamelessly stole his code and regularly use
it in my own projects. ;-}
Paul
Paul:
Thanks for the plug.
All the code I provide on this list and on my various web sites is
for free for anyone, except for "governments" (i.e., local, state,
federal, other), to use, review, and/or comment as they wish without
any obligation to me. Oh, as for "governments" if you want a copy of
anything please contact me directly, I have a few forms for you to
fill out.
The point of sharing is to improve product -- agile works.
My livelihood is not compromised because someone is using a small
snip-it of mine. Hopefully my real code (the stuff I sell to clients)
is more involved and has more value than that.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
At 4:37 PM +0200 4/30/10, Jay Ess wrote:
Paul M Foster wrote:
+1
This thread came up before, and tedd's solution was the least complex,
as far as I could tell. I shamelessly stole his code and regularly use
it in my own projects. ;-}
Or if one choose to use Smarty template.
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
http://www.smarty.net/manual/en/language.function.cycle.php
Yeah, like that keeps presentation separate from data while making
things simpler, right? I don't think so.
Embedding styling attributes in html is simply not following "best practices".
For example, if you have 100 pages of the above embedded code and the
client says "Hey, let's change the color of that table" -- then you
are going to have to change 100 pages of code whereas if you followed
"best practices" then you would change only one rule in css.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Fri, 2010-04-30 at 13:59 -0400, tedd wrote:
> At 4:37 PM +0200 4/30/10, Jay Ess wrote:
> >Paul M Foster wrote:
> >>+1
> >>
> >>This thread came up before, and tedd's solution was the least complex,
> >>as far as I could tell. I shamelessly stole his code and regularly use
> >>it in my own projects. ;-}
> >>
> >Or if one choose to use Smarty template.
> ><tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
> >
> >http://www.smarty.net/manual/en/language.function.cycle.php
>
> Yeah, like that keeps presentation separate from data while making
> things simpler, right? I don't think so.
>
> Embedding styling attributes in html is simply not following "best practices".
>
> For example, if you have 100 pages of the above embedded code and the
> client says "Hey, let's change the color of that table" -- then you
> are going to have to change 100 pages of code whereas if you followed
> "best practices" then you would change only one rule in css.
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
I agree. Inline styles are useful in a few fringe cases, but if you can
avoid them then it's best practice to do so.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
At 7:26 PM +0100 4/30/10, Ashley Sheridan wrote:
On Fri, 2010-04-30 at 13:59 -0400, tedd wrote:
At 4:37 PM +0200 4/30/10, Jay Ess wrote:
Paul M Foster wrote:
+1
This thread came up before, and tedd's solution was the least complex,
as far as I could tell. I shamelessly stole his code and regularly use
it in my own projects. ;-}
Or if one choose to use Smarty template.
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
<http://www.smarty.net/manual/en/language.function.cycle.php>http://www.smarty.net/manual/en/language.function.cycle.php
Yeah, like that keeps presentation separate from data while making
things simpler, right? I don't think so.
Embedding styling attributes in html is simply not following "best
practices".
For example, if you have 100 pages of the above embedded code and the
client says "Hey, let's change the color of that table" -- then you
are going to have to change 100 pages of code whereas if you followed
"best practices" then you would change only one rule in css.
Cheers,
tedd
I agree. Inline styles are useful in a few fringe cases, but if you
can avoid them then it's best practice to do so.
Thanks,
Ash
<http://www.ashleysheridan.co.uk>http://www.ashleysheridan.co.uk
Ash:
The only "fringe" cases I can think of are those that could be solved
by using a <span> tag.
Do you have any examples otherwise?
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Fri, 2010-04-30 at 15:59 -0400, tedd wrote:
> At 7:26 PM +0100 4/30/10, Ashley Sheridan wrote:
> >>On Fri, 2010-04-30 at 13:59 -0400, tedd wrote:
> >>At 4:37 PM +0200 4/30/10, Jay Ess wrote:
> >>>Paul M Foster wrote:
> >>>>+1
> >>>>
> >>>>This thread came up before, and tedd's solution was the least complex,
> >>>>as far as I could tell. I shamelessly stole his code and regularly use
> >>>>it in my own projects. ;-}
> >>>>
> >>>Or if one choose to use Smarty template.
> >>><tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
> >>>
> >>><http://www.smarty.net/manual/en/language.function.cycle.php>http://www.smarty.net/manual/en/language.function.cycle.php
> >>
> >>Yeah, like that keeps presentation separate from data while making
> >>things simpler, right? I don't think so.
> >>
> >>Embedding styling attributes in html is simply not following "best
> >>practices".
> >>
> >>For example, if you have 100 pages of the above embedded code and the
> >>client says "Hey, let's change the color of that table" -- then you
> >>are going to have to change 100 pages of code whereas if you followed
> >>"best practices" then you would change only one rule in css.
> >>
> >>Cheers,
> >>
> >>tedd
>
> >I agree. Inline styles are useful in a few fringe cases, but if you
> >can avoid them then it's best practice to do so.
> >
> >Thanks,
> >Ash
> ><http://www.ashleysheridan.co.uk>http://www.ashleysheridan.co.uk
>
> Ash:
>
> The only "fringe" cases I can think of are those that could be solved
> by using a <span> tag.
>
> Do you have any examples otherwise?
>
> Cheers,
>
> tedd
I can't think of any right now, but I know that on occassion I've used
inline styles where I know that the style will never be repeated and was
a one-off style to just perform a quick fix. I know it's a messy thing
to do, but I'm sure there must be a good reason for them somewhere!
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
>
> Modulus is the most elegant solution I reckon. Imagine if you only
> needed to highlight every 3rd row, or 4th? Easy to change the modulus
> for it, not so easy to re-work a binary switch.
>
> -----Original Message-----
> From: Richard Quadling [mailto:rquadl...@googlemail.com]
>
> The modulus is a good option when there are more than 2 states.
>
> Say a 5 row fade ...
>
> $a=0;
> while ($row=mysql_fetch_...){
> echo "<tr class=??????\"alternate-row-".(1 + (++$a%5))."\"><..."
> }
>
> giving alternate-row-1, alternate-row-2, alternate-row-3,
> alternate-row-4 and alternate-row-5
Okay, how many tables do you EVER see with more than TWO colors? Come on
now.
Show me some URL's to REAL sites (not some contrived examples) that use
multiple row colors or fades in a rotating fashion. Not talking about a
highlight roll-over, nor am I talking about highlighting rows of certain
criteria in different colors, as both of those are not the problem for this
solution. I'm talking about a straight up table that cycles each row more
than 2 colors.
99% of your tables are 2 colors, and flipping a bit (i.e. Boolean) is WAY
faster to compute than modulus and also easier to understand.
http://www.youtube.com/watch?v=pXhKzY0BKwY ;-) (I say that out of love!)
d
--- End Message ---
--- Begin Message ---
On Apr 30, 2010, at 4:20 PM, Daevid Vincent wrote:
-----Original Message-----
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Modulus is the most elegant solution I reckon. Imagine if you only
needed to highlight every 3rd row, or 4th? Easy to change the modulus
for it, not so easy to re-work a binary switch.
-----Original Message-----
From: Richard Quadling [mailto:rquadl...@googlemail.com]
The modulus is a good option when there are more than 2 states.
Say a 5 row fade ...
$a=0;
while ($row=mysql_fetch_...){
echo "<tr class=??????\"alternate-row-".(1 + (++$a%5))."\"><..."
}
giving alternate-row-1, alternate-row-2, alternate-row-3,
alternate-row-4 and alternate-row-5
Okay, how many tables do you EVER see with more than TWO colors?
Come on
now.
Show me some URL's to REAL sites (not some contrived examples) that
use
multiple row colors or fades in a rotating fashion. Not talking
about a
highlight roll-over, nor am I talking about highlighting rows of
certain
criteria in different colors, as both of those are not the problem
for this
solution. I'm talking about a straight up table that cycles each row
more
than 2 colors.
99% of your tables are 2 colors, and flipping a bit (i.e. Boolean)
is WAY
faster to compute than modulus and also easier to understand.
http://www.youtube.com/watch?v=pXhKzY0BKwY ;-) (I say that out of
love!)
A bit of a contrived example... BUT... I could envision having
multiple (more then 2) colors on a blog with comments...
Maybe it's a patriotic blog and they want the comments to cycle
between red, white & blue... (Or your countries colors) And yes I know
that you could assume white is a default... But I know some people who
have the default color of their web browser set to bright pink to
point out where rules aren't specifically assigned :)
And unless we are adding a multiple seconds to the load time is anyone
going to notice a difference of 1 second? Or am I wrong?
Also... I'm not trying to start a fight... Just trying to understand
the different possibilities and the impact :) Hoping to write the next
facebook eventually.... But aren't we all? ;)
--- End Message ---
--- Begin Message ---
hello everybody here is my array(s)
$us_census = array('NY' => array('New York' => 8008278),
'CA' => array('Los Angeles' => 3694820,
'San Diego' =>
1223400),
'IL' => array('Chicago' => 2896016),
'TX' => array('Houston' => 1953631,
'Dallas' =>
1188580,
'San Antonio'
=> 1144646),
'PA' => array('Philadelphia' => 1517550),
'AZ' => array('Phoenix' => 1321045),
'MI' => array('Detroit' => 951270));
print
"<table><tr><th>State</th><th>City</th><th>Population</th><th>Total</th></tr>";
// $state is the key and $states is the value
foreach ($us_census as $state => $cities) {
// $state is the key and $habitant is the value
foreach ($cities as $city => $habitants){
print
"<tr><td>$state</td><td>$city</td><td>$habitants</td><td></td></tr>";
}
}
Now i also want to be able to count the total population per state, i am
stucked...
--- End Message ---
--- Begin Message ---
Am 01.05.2010 00:57, schrieb Nick Balestra:
> hello everybody here is my array(s)
>
>
> $us_census = array('NY' => array('New York' => 8008278),
> 'CA' => array('Los Angeles' => 3694820,
> 'San Diego' =>
> 1223400),
> 'IL' => array('Chicago' => 2896016),
> 'TX' => array('Houston' => 1953631,
> 'Dallas' =>
> 1188580,
> 'San Antonio'
> => 1144646),
> 'PA' => array('Philadelphia' => 1517550),
> 'AZ' => array('Phoenix' => 1321045),
> 'MI' => array('Detroit' => 951270));
>
>
>
> print
> "<table><tr><th>State</th><th>City</th><th>Population</th><th>Total</th></tr>";
>
>
> // $state is the key and $states is the value
> foreach ($us_census as $state => $cities) {
>
> // $state is the key and $habitant is the value
> foreach ($cities as $city => $habitants){
>
>
>
> print
> "<tr><td>$state</td><td>$city</td><td>$habitants</td><td></td></tr>";
>
>
> }
> }
>
>
> Now i also want to be able to count the total population per state, i am
> stucked...
>
array_sum() should do it :)
foreach ($us_census as $state => $cities) {
$population_per_state = array_sum($cities);
}
--- End Message ---
--- Begin Message ---
thanks Piero!
i was trying to solve an excercise on "learning php5" (O'reilyl) book.
I am happy abotut his solution with the array_sum funtion you suggested, and my
multidimensional array make much more sense to mee then they suggested solution
that also much more line of code comapred...
look: my solution (with Piero suggeston): and ont he bottom the book solution.
what do u say is the best one? why? i am learning so i am interested in
understanding why a solution can be better then an other...
$us_census = array('NY' => array('New York' => 8008278),
'CA' => array('Los Angeles' => 3694820,
'San Diego' =>
1223400),
'IL' => array('Chicago' => 2896016),
'TX' => array('Houston' => 1953631,
'Dallas' =>
1188580,
'San Antonio'
=> 1144646),
'PA' => array('Philadelphia' => 1517550),
'AZ' => array('Phoenix' => 1321045),
'MI' => array('Detroit' => 951270));
print
"<table><tr><th>State</th><th>City</th><th>Population</th><th>Total</th></tr>";
foreach ($us_census as $state => $cities) {
foreach ($cities as $city => $habitants){
$tothabitants += $habitants;
print
"<tr><td>$state</td><td>$city</td><td>$habitants</td><td></td></tr>";
}
}
print "<tr><td></td><td></td><td></td><td>$tothabitants</td></tr></table>";
foreach ($us_census as $state => $cities) {
$population_per_state = array_sum($cities);
print "$state $population_per_state<br>";
}
--------------------------
the book solution:
$population = array('New York' => array('state' => 'NY', 'pop' => 8008278),
'Los Angeles' => array('state' => 'CA', 'pop' => 3694820),
'Chicago' => array('state' => 'IL', 'pop' => 2896016),
'Houston' => array('state' => 'TX', 'pop' => 1953631),
'Philadelphia' => array('state' => 'PA', 'pop' => 1517550),
'Phoenix' => array('state' => 'AZ', 'pop' => 1321045),
'San Diego' => array('state' => 'CA', 'pop' => 1223400),
'Dallas' => array('state' => 'TX', 'pop' => 1188580),
'San Antonio' => array('state' => 'TX', 'pop' => 1144646),
'Detroit' => array('state' => 'MI', 'pop' => 951270));
$state_totals = array( );
$total_population = 0;
print "<table><tr><th>City</th><th>Population</th></tr>\n";
foreach ($population as $city => $info) {
$total_population += $info['pop'];
$state_totals[$info['state']] += $info['pop'];
print "<tr><td>$city, {$info['state']}</td><td>{$info['pop']}</td></tr>\n";
}
foreach ($state_totals as $state => $pop) {
print "<tr><td>$state</td><td>$pop</td>\n";
}
print "<tr><td>Total</td><td>$total_population</td></tr>\n";
print "</table>\n";
--- End Message ---
--- Begin Message ---
I have this duplicate code on another site and it works fine. The image is
uploaded to the images folder, the information is not submitted to the
database. I get the error
Some Error Occured While Inserting Records
This is only on a local machine so I have not yet included and safegaurds
like stripslashes or my_real_escape_string.
Thanks for your help
Gary
<?php
if (isset($_POST['submit'])) {
$manufacturer=($_POST['manufacturer']);
$type=($_POST['type']);
$model=($_POST['model']);
$caliber=($_POST['caliber']);
$condition=($_POST['condition']);
$price=($_POST['price']);
$description=($_POST['description']);
$image_file_name=($_POST['image_file_name']);
$image_file=($_FILES['image_file']);
$available=($_POST['available']);
$image_file = $_FILES['image_file']['name'];
$image_type = $_FILES['image_file']['type'];
$image_size = $_FILES['image_file']['size'];
include ('includes/connect_local.inc.php');
if(image_size >3000000) {
class ImgResizer {
private $originalFile = 'image_file';
public function __construct($originalFile = 'image_file') {
$this -> originalFile = $originalFile;
}
public function resize($newWidth, $targetFile) {
if (empty($newWidth) || empty($targetFile)) {
return false;
}
$src = imagecreatefromjpeg($this -> originalFile);
list($width, $height) = getimagesize($this -> originalFile);
$newHeight = ($height / $width) * $newWidth;
$tmp = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width,
$height);
if (file_exists($targetFile)) {
unlink($targetFile);
}
imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 -
100 for output image quality with 100 being the most luxurious
}
}
}
if (!empty($type) && !empty($image_file)) {
if (($image_type == 'image/gif') || ($image_type == 'image/jpeg') ||
($image_type == 'image/pjpeg') || ($image_type == 'image/png') &&
($image_size <3000000)) {
if ($_FILES['image_file']['error'] == 0) {
// Move the file to the target upload folder
$target = 'images/' . $image_file;
if (move_uploaded_file($_FILES['image_file']['tmp_name'],
$target)){
$batchconnection;
$sqlStatements = "INSERT INTO guns( id,manufacturer, type, model,
caliber, condition, price, description, image_file_name,submitted
,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber',
'$condition', '$price', '$description','$image_file_name', ' ',
'$available');
INSERT INTO images (id, image_file) VALUES('','$image_file')";
$sqlResult = $batchconnection->multi_query($sqlStatements);
if($sqlResult == true) {
echo "Successfully Inserted Records";
} else {
echo "Some Error Occured While Inserting Records";
}
}
}
}
}
mysqli_close($batchconnection);
}
?>
__________ Information from ESET Smart Security, version of virus signature
database 5076 (20100430) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
On Fri, 2010-04-30 at 20:43 -0400, Gary wrote:
> I have this duplicate code on another site and it works fine. The image is
> uploaded to the images folder, the information is not submitted to the
> database. I get the error
>
> Some Error Occured While Inserting Records
>
> This is only on a local machine so I have not yet included and safegaurds
> like stripslashes or my_real_escape_string.
>
> Thanks for your help
>
> Gary
>
> <?php
> if (isset($_POST['submit'])) {
> $manufacturer=($_POST['manufacturer']);
> $type=($_POST['type']);
> $model=($_POST['model']);
> $caliber=($_POST['caliber']);
> $condition=($_POST['condition']);
> $price=($_POST['price']);
> $description=($_POST['description']);
> $image_file_name=($_POST['image_file_name']);
> $image_file=($_FILES['image_file']);
> $available=($_POST['available']);
>
> $image_file = $_FILES['image_file']['name'];
> $image_type = $_FILES['image_file']['type'];
> $image_size = $_FILES['image_file']['size'];
>
> include ('includes/connect_local.inc.php');
>
> if(image_size >3000000) {
>
> class ImgResizer {
> private $originalFile = 'image_file';
> public function __construct($originalFile = 'image_file') {
> $this -> originalFile = $originalFile;
> }
> public function resize($newWidth, $targetFile) {
> if (empty($newWidth) || empty($targetFile)) {
> return false;
> }
> $src = imagecreatefromjpeg($this -> originalFile);
> list($width, $height) = getimagesize($this -> originalFile);
> $newHeight = ($height / $width) * $newWidth;
> $tmp = imagecreatetruecolor($newWidth, $newHeight);
> imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width,
> $height);
> if (file_exists($targetFile)) {
> unlink($targetFile);
> }
> imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 -
> 100 for output image quality with 100 being the most luxurious
> }
> }
> }
> if (!empty($type) && !empty($image_file)) {
> if (($image_type == 'image/gif') || ($image_type == 'image/jpeg') ||
> ($image_type == 'image/pjpeg') || ($image_type == 'image/png') &&
> ($image_size <3000000)) {
> if ($_FILES['image_file']['error'] == 0) {
> // Move the file to the target upload folder
> $target = 'images/' . $image_file;
> if (move_uploaded_file($_FILES['image_file']['tmp_name'],
> $target)){
> $batchconnection;
>
> $sqlStatements = "INSERT INTO guns( id,manufacturer, type, model,
> caliber, condition, price, description, image_file_name,submitted
> ,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber',
> '$condition', '$price', '$description','$image_file_name', ' ',
> '$available');
>
> INSERT INTO images (id, image_file) VALUES('','$image_file')";
>
> $sqlResult = $batchconnection->multi_query($sqlStatements);
> if($sqlResult == true) {
> echo "Successfully Inserted Records";
> } else {
> echo "Some Error Occured While Inserting Records";
> }
>
>
>
> }
>
> }
> }
> }
> mysqli_close($batchconnection);
> }
> ?>
>
>
>
> __________ Information from ESET Smart Security, version of virus signature
> database 5076 (20100430) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
Is it possible that this server doesn't like batch queries? Try
splitting them out into individual queries and seeing if that helps. If
that doesn't do the trick, print out the SQL query string to see if it's
what you expect. It might be working fine on the other server, but I've
seen enough strange things happen before to know that sometimes 'poo'
happens.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
This is the other code that works on the same server.
<?php
if (isset($_POST['submit'])) {
$caption=($_POST['caption']);
$description=($_POST['description']);
$image_file=($_FILES['image_file']);
$where_taken=($_POST['where_taken']);
$fox=($_POST['fox']);
$wolves=($_POST['wolves']);
$wildlife=($_POST['wildlife']);
$scenic=($_POST['scenic']);
$birds=($_POST['birds']);
$eagles=($_POST['eagles']);
$deer=($_POST['deer']);
$small_mammals=($_POST['small_mammals']);
$large_mammals=($_POST['large_mammals']);
$dogs=($_POST['dogs']);
$cats=($_POST['cats']);
$flowers=($_POST['flowers']);
$insects=($_POST['insects']);
$bear=($_POST['bear']);
$moose=($_POST['moose']);
$image_file = $_FILES['image_file']['name'];
$image_type = $_FILES['image_file']['type'];
$image_size = $_FILES['image_file']['size'];
include('includes/connect_local.inc.php');
if(image_size > 3000000) {
class ImgResizer {
private $originalFile = '';
public function __construct($originalFile = '') {
$this -> originalFile = $originalFile;
}
public function resize($newWidth, $targetFile) {
if (empty($newWidth) || empty($targetFile)) {
return false;
}
$src = imagecreatefromjpeg($this -> originalFile);
list($width, $height) = getimagesize($this -> originalFile);
$newHeight = ($height / $width) * $newWidth;
$tmp = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width,
$height);
if (file_exists($targetFile)) {
unlink($targetFile);
}
imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 -
100 for output image quality with 100 being the most luxurious
}
}
}
if (!empty($caption) && !empty($image_file)) {
if (($image_type == 'image/gif') || ($image_type == 'image/jpeg') ||
($image_type == 'image/pjpeg') || ($image_type == 'image/png') &&
($image_size < 3000000)) {
if ($_FILES['image_file']['error'] == 0) {
// Move the file to the target upload folder
$target = 'images/' . $image_file;
if (move_uploaded_file($_FILES['image_file']['tmp_name'],
$target)){
$batchconnection;
$sqlStatements = "INSERT INTO images(caption,
where_taken,description, image_file) VALUES
('$caption','$where_taken','$description','$image_file');
INSERT INTO keywords (image_id,fox, wolves, wildlife, scenic, birds, eagles,
deer, small_mammals, large_mammals, dogs, cats, flowers, insects, bear,
moose)
VALUES('','$fox','$wolves','$wildlife','$scenic','$birds','$eagles','$deer',
'$small_mammals', '$large_mammals','$dogs', '$cats', '$flowers', '$insects',
'$bear', '$moose')";
$sqlResult = $batchconnection->multi_query($sqlStatements);
if($sqlResult == true) {
echo "Successfully Inserted Records";
} else {
echo "Some Error Occured While Inserting Records";
}
mysqli_close($batchconnection);
}
}
}
}
}
?>
"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
news:1272674704.9998.11.ca...@localhost...
> On Fri, 2010-04-30 at 20:43 -0400, Gary wrote:
>
>> I have this duplicate code on another site and it works fine. The image
>> is
>> uploaded to the images folder, the information is not submitted to the
>> database. I get the error
>>
>> Some Error Occured While Inserting Records
>>
>> This is only on a local machine so I have not yet included and safegaurds
>> like stripslashes or my_real_escape_string.
>>
>> Thanks for your help
>>
>> Gary
>>
>> <?php
>> if (isset($_POST['submit'])) {
>> $manufacturer=($_POST['manufacturer']);
>> $type=($_POST['type']);
>> $model=($_POST['model']);
>> $caliber=($_POST['caliber']);
>> $condition=($_POST['condition']);
>> $price=($_POST['price']);
>> $description=($_POST['description']);
>> $image_file_name=($_POST['image_file_name']);
>> $image_file=($_FILES['image_file']);
>> $available=($_POST['available']);
>>
>> $image_file = $_FILES['image_file']['name'];
>> $image_type = $_FILES['image_file']['type'];
>> $image_size = $_FILES['image_file']['size'];
>>
>> include ('includes/connect_local.inc.php');
>>
>> if(image_size >3000000) {
>>
>> class ImgResizer {
>> private $originalFile = 'image_file';
>> public function __construct($originalFile = 'image_file') {
>> $this -> originalFile = $originalFile;
>> }
>> public function resize($newWidth, $targetFile) {
>> if (empty($newWidth) || empty($targetFile)) {
>> return false;
>> }
>> $src = imagecreatefromjpeg($this -> originalFile);
>> list($width, $height) = getimagesize($this -> originalFile);
>> $newHeight = ($height / $width) * $newWidth;
>> $tmp = imagecreatetruecolor($newWidth, $newHeight);
>> imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight,
>> $width,
>> $height);
>> if (file_exists($targetFile)) {
>> unlink($targetFile);
>> }
>> imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between
>> 0 -
>> 100 for output image quality with 100 being the most luxurious
>> }
>> }
>> }
>> if (!empty($type) && !empty($image_file)) {
>> if (($image_type == 'image/gif') || ($image_type == 'image/jpeg')
>> ||
>> ($image_type == 'image/pjpeg') || ($image_type == 'image/png') &&
>> ($image_size <3000000)) {
>> if ($_FILES['image_file']['error'] == 0) {
>> // Move the file to the target upload folder
>> $target = 'images/' . $image_file;
>> if (move_uploaded_file($_FILES['image_file']['tmp_name'],
>> $target)){
>> $batchconnection;
>>
>> $sqlStatements = "INSERT INTO guns( id,manufacturer, type, model,
>> caliber, condition, price, description, image_file_name,submitted
>> ,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber',
>> '$condition', '$price', '$description','$image_file_name', ' ',
>> '$available');
>>
>> INSERT INTO images (id, image_file) VALUES('','$image_file')";
>>
>> $sqlResult = $batchconnection->multi_query($sqlStatements);
>> if($sqlResult == true) {
>> echo "Successfully Inserted Records";
>> } else {
>> echo "Some Error Occured While Inserting Records";
>> }
>>
>>
>>
>> }
>>
>> }
>> }
>> }
>> mysqli_close($batchconnection);
>> }
>> ?>
>>
>>
>>
>> __________ Information from ESET Smart Security, version of virus
>> signature database 5076 (20100430) __________
>>
>> The message was checked by ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>>
>
>
> Is it possible that this server doesn't like batch queries? Try
> splitting them out into individual queries and seeing if that helps. If
> that doesn't do the trick, print out the SQL query string to see if it's
> what you expect. It might be working fine on the other server, but I've
> seen enough strange things happen before to know that sometimes 'poo'
> happens.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 5076 (20100430) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
__________ Information from ESET Smart Security, version of virus signature
database 5076 (20100430) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
may be it is not the error with the code. The problem may be with some
' in the input. Print out the mysql error and/or the sql query to see
what is going wrong.
--- End Message ---