Jump to content

error with photo gallery


silverglade

Recommended Posts

Hi I am getting the following error for my php photo gallery. I am following a tutorial. Any help greatly appreciated. Thank you. I have commented what I think is wrong, but I don't know how to fix it.

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/index2.php on line 6

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/index2.php on line 10

 

 

 

<?php
require_once('globals.php');


    $query = sprintf('select image_id, filename from images');//THIS SEEMS TO BE THE PROBLEM
    $result = mysql_query($query, $db);

    $images = array();

    while ($row = mysql_fetch_array($result)) {
        $id = $row['image_id'];
        $images[$id] = $row['filename'];
    }
?>
<html>
    <head>
        <title>Uploaded Images</title>
    </head>
    <body>
        <div>
            <h1>Uploaded Images</h1>

            <p>
                <a href="upload.php">Upload an image</a>
            </p>

            <ul>
                <?php if (count($images) == 0) { ?>
                    <li>No uploaded images found</li>
                <?php } else foreach ($images as $id => $filename) { ?>
                    <li>
                        <a href="view.php?id=<?php echo $id ?>">
                            <?php echo htmlSpecialChars($filename)  ?>
                        </a>
                    </li>
                <?php } ?>
            </ul>
    </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/241143-error-with-photo-gallery/
Share on other sites

 

 

EDIT: wait i see an error in the table name LOL.

 

 

 

Thank you. Here is my "globals.php " contents. I fixed it but don't understand why it's not working. I made $db = "photo_artists".

 

Here are the contents

 

<?php

$host		= " ";
$db = "photo_artists";//database name
$username 	= " ";
$password 	= " ";
$tbl_name   = "users";
mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());
mysql_select_db($db);
?>

 

I still get the error. Any more help appreciated. thank you!  :)

you are misunderstanding, but its okay here's what you would want

 

<?php

$host		= " ";
$username 	= " ";
$password 	= " ";
$tbl_name   = "users";
$db = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());
mysql_select_db("photo_artists");
?>

also, you will need to fill in the $host $username and $password information with the valid information for your server unless they are not set

awesome thank you so much. I think ,  I hope this is my last error, I googled it and it has to do with white spaces I think, but I don't see any unnecessary white space in the file. Here is the error, please, any more help would be great. thanks for helping. I am trying to upload an image now with process.php.

 

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/process.php:1) in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/process.php on line 89

 

 

 <?php
   require_once('globals.php');
   
   
    function assertValidUpload($code)
    {
        if ($code == UPLOAD_ERR_OK) {
            return;
        }

        switch ($code) {
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
                $msg = 'Image is too large';
                break;

            case UPLOAD_ERR_PARTIAL:
                $msg = 'Image was only partially uploaded';
                break;

            case UPLOAD_ERR_NO_FILE:
                $msg = 'No image was uploaded';
                break;

            case UPLOAD_ERR_NO_TMP_DIR:
                $msg = 'Upload folder not found';
                break;

            case UPLOAD_ERR_CANT_WRITE:
                $msg = 'Unable to write uploaded file';
                break;

            case UPLOAD_ERR_EXTENSION:
                $msg = 'Upload failed due to extension';
                break;

            default:
                $msg = 'Unknown error';
        }

        throw new Exception($msg);
    }

    $errors = array();

    try {
        if (!array_key_exists('image', $_FILES)) {
            throw new Exception('Image not found in uploaded data');
        }

        $image = $_FILES['image'];

        // ensure the file was successfully uploaded
        assertValidUpload($image['error']);

        if (!is_uploaded_file($image['tmp_name'])) {
            throw new Exception('File is not an uploaded file');
        }

        $info = getImageSize($image['tmp_name']);

        if (!$info) {
            throw new Exception('File is not an image');
        }
    }
    catch (Exception $ex) {
        $errors[] = $ex->getMessage();
    }

    if (count($errors) == 0) {
        // no errors, so insert the image

        $query = sprintf(
            "insert into images (filename, mime_type, file_size, file_data)
                values ('%s', '%s', %d, '%s')",
            mysql_real_escape_string($image['name']),
            mysql_real_escape_string($info['mime']),
            $image['size'],
            mysql_real_escape_string(
                file_get_contents($image['tmp_name'])
            )
        );

        mysql_query($query, $db);

        $id = (int) mysql_insert_id($db);

        // finally, redirect the user to view the new image
        header('Location: view.php?id=' . $id);
        exit;
    }
?><html>
    <head>
        <title>Error</title>
    </head>
    <body>
        <div>
            <p>
                The following errors occurred:
            </p>

            <ul>
                <?php foreach ($errors as $error) { ?>
                    <li>
                        <?php echo htmlSpecialChars($error) ?>
                    </li>
                <?php } ?>
            </ul>

            <p>
                <a href="upload.php">Try again</a>
            </p>
        </div>
    </body>
    </html>

sorry. I read it and I don't understand what they are telling me to do. This is what it says to do.

 

 

"answer:  put the processing in the header, and store the results in variables.  perhaps a $result variable that is 1 if successful, 0 if failed.  then $output that contains either a success message or customized error messages.  the new code would look like:

 


[html starting the page and layout]
[php echoing the results]
[form code if failed - exit(); if successful]
"

I have used the header function before and had it under the php in an include file like this and it worked.


[code]<?php
session_start();/
/*echo '<pre>';
print_r($_SESSION);
echo '</pre>';
exit;*//// 
//print_r($_SESSION);
//print_r(session_get_cookie_params());
if(!isset($_SESSION["userid"])){ 

header("Location:index.php?hack=y"); 


exit;
}

?>[/code]

Here's your error message - headers already sent by (output started at /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/process.php:1) in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/process.php on line 89

 

Based on the code you posted, you have a space or some other character before the <?php tag that is on line 1. You cannot output any characters to the browser before you do something that requires a http header.

Archived

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

×
×
  • 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.