Jump to content

Recommended Posts

This thread is based on [a href=\"http://aimmultimedia.com/viewpage.php?page_id=3\" target=\"_blank\"]http://aimmultimedia.com/viewpage.php?page_id=3[/a] , where there are couple of problems. (Try uploading for yourself).

First problem: My first query runs perfectly, but my 2nd mysql query doesn't. Whats wrong?

First Query
PHP Code:[code]
$viewid = $_GET["id"];
$result = mysql_query("SELECT * FROM registered_files WHERE viewid = '$viewid'");
$myrow = mysql_fetch_array($result);
[/code]

Second Query
PHP Code:
[code]<?php $result2  = mysql_query("UPDATE registered_files SET hits=hits+1 WHERE id = '$viewid'") or die (mysql_error());
$rowyourboat = mysql_fetch_array($result2);
echo $rowyourboat["hits"] ?>[/code]


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lpxxfain/public_html/membersimage.php on line 36[/quote]




Second Question: On the same upload page, I recently installed a watermarking system, and it works fine. The problem is when it watermarks small images, it totally messes it up. Is there any way so that it doesn't water mark images that are too small?

Example Normal : [a href=\"http://aimmultimedia.com/membersimage.php?id=Gdubs!4\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=Gdubs!4[/a]
Example Small : [a href=\"http://aimmultimedia.com/membersimage.php?id=Affiliate8\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=Affiliate8[/a]


Source:

function_watermark.php
PHP Code:
[code]<?php

function watermark($SourceFile, $WatermarkFile, $SaveToFile = NULL)

{

    $watermark = @imagecreatefrompng($WatermarkFile)


    or exit('Cannot open the watermark file.');

    imageAlphaBlending($watermark, false);

    imageSaveAlpha($watermark, true);

    $image_string = @file_get_contents($SourceFile)


    or exit('Cannot open image file.');

    $image = @imagecreatefromstring($image_string)

    or exit('Not a valid image format.');

    $imageWidth=imageSX($image);

    $imageHeight=imageSY($image);


    $watermarkWidth=imageSX($watermark);

    $watermarkHeight=imageSY($watermark);

    $coordinate_X = ( $imageWidth - 5) - ( $watermarkWidth);


    $coordinate_Y = ( $imageHeight - 5) - ( $watermarkHeight);

    imagecopy($image, $watermark, $coordinate_X, $coordinate_Y,


        0, 0, $watermarkWidth, $watermarkHeight);

    if(!($SaveToFile)) header('Content-Type: image/jpeg');

    imagejpeg ($image, $SaveToFile, 100);


    imagedestroy($image);

    imagedestroy($watermark);

    if(!($SaveToFile)) exit;

}

?>[/code]




membersupload.php
PHP Code:
[code]<?php
ob_start();

UPLOAD CODE WAS HERE

header("Location: http://aimmultimedia.com/process2.php?id=$id&ext=$ext&viewid=$viewid");

};
ob_end_flush();


?>
[/code]



Process2.php
PHP Code:
[code]<?php
ob_start();
// The image should be located in a non public directory
$id = $_GET['id'];
$ext = $_GET['ext'];
$viewid = $_GET['viewid'];


$image_location = '/home/lpxxfain/public_html/members/images/'.$id. '.' .$ext;



// Locate the watermark file wherever you choose (remember PNG format)

$watermark_location = '/home/lpxxfain/public_html/members/water.png';



// Location where you want to save the created watermarked file

$save_watermarked_file_to = '/home/lpxxfain/public_html/members/images/imagesbin/'.$id. '.' .$ext;




// Include the watermarking function file

require_once($_SERVER['DOCUMENT_ROOT'] . '/function_watermark.php');



// Watermark the image and save it to file

watermark($image_location, $watermark_location, $save_watermarked_file_to);

header("Location: http://aimmultimedia.com/membersimage.php?id=$viewid");
ob_end_flush();

?>[/code]




3rd Question: Is there any way so that if there is no $_GET['editid'] then the script runs normally, and when there is a $_GET it run's something different?



Help would be greatly appreciated.

-AIMMultimedia.com
Link to comment
https://forums.phpfreaks.com/topic/5919-watermarking-mysql-php-problems/
Share on other sites

[!--quoteo(post=358856:date=Mar 27 2006, 12:24 PM:name=lpxxfaintxx)--][div class=\'quotetop\']QUOTE(lpxxfaintxx @ Mar 27 2006, 12:24 PM) [snapback]358856[/snapback][/div][div class=\'quotemain\'][!--quotec--]
No, it's fixed. ;)
[/quote]

Can you post the fix for other users like me cheers.

I was getting right into your site untill i relise that you got a 3rd party script lol.
cool!

All the best redarrow.
the whole thing fixed? or just that error i stated?

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php $result2 = mysql_query("UPDATE registered_files SET hits=hits+1 WHERE id = '$viewid'") or die (mysql_error());
$rowyourboat = mysql_fetch_array($result2);
echo $rowyourboat["hits"] ?>[/quote]

You can't echo an array of this because it's an update therefore is doesn't select any data you will need

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
$result2 = mysql_query("UPDATE registered_files SET hits=(hits+1) WHERE id = '$viewid'") or die (mysql_error());
$result3 = mysql_query("SELECT hits FROM registered_files WHERE id = '$viewid'") or die (mysql_error());
$rowyourboat = mysql_fetch_array($result3);
echo $rowyourboat["hits"] ?>
[/quote]


That should do the job mate :)
Well, the error is gone but it just comes out as nothing. Preview: [a href=\"http://aimmultimedia.com/membersimage.php?id=asgdsgdsaga10\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=asgdsgdsaga10[/a]

I have the tables set up correctly, I am almost certain. I have the 'hits' field on int(10)

Also, does anyone have any ideas about the other questions, like the watermarking one?

Thanks a LOT.
On the water marking....

I think I saw in the script that you grab the dimensions of each image. Simple if statement to check the watermark is smaller than the image - if it is use the watermark - if not do something else (I suggest you just put some text on), or nothing.

Your first problem with the query has been sorted out.

The final one about whether $_GET['editid'] is set....

another if statment...

if (isset($_GET['editid'] )) {
do something
} else {
do soemthing else
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.