Jump to content

Recommended Posts

I'm using some code to load and view images, when I try to upload images, it says Table 'image-store.images' doesn't exist which really confuses me because my table is called image-store and I've got a field called images so what could be the reasons for this?

 

My code if it helps...

 

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
if(isset($_POST['imageInsert']))
{
   function checkUrl($url)
    {
        if(@file_get_contents($url))
        {
            return TRUE;
        }
        else
        {
            return FALSE;    
        }
    }
    
    
    $con = mysql_connect("localhost", "root", "");
    $db = mysql_select_db("image-store", $con);
    $url = $_POST['url'];

    if(preg_match("#((\.jpeg)|(\.jpg)|(\.gif)|(\.png))$#is", $url, $match))
    {
        if($match[1]==".jpg")
        {
            $ext = ".jpeg";
        }
        else
        {
            $ext = trim($match[1]);
        }
        $ext = substr($ext, 1);
        if(checkUrl($_POST['url']))
        {
            
            $image = mysql_real_escape_string(file_get_contents($_POST['url']));
            if(mysql_query("INSERT INTO `images` (image, ext) VALUES ('$image', '$ext') ") or die (mysql_error()))
            {
                echo "insert complete";
            }
            else
            {
                echo "could not insert error occured";    
            }
        }
        else
        {
            echo "url incorrect";    
        }
    }
    else
    {
        echo "invalid file type";    
    }
}
elseif(isset($_POST['imageShow']))
{
    $src = "imageLoader.php?id=".$_POST['id'];
    echo "<h2>Show Image: ID#".$_POST['id']."</h2>\n";
    echo "<img src=\"".$src."\" />\n";
}
else
{
    echo "<h2>No image Selected To Show</h2>\n";    
}
?>

<h2>Upload Image</h2>
<form method="post" action="index.php">
    url: <input type="text" name="url" />
    <input type="submit" name="imageInsert" />
</form>

<h2>Show image</h2>
<form method="post" action="index.php">
    id: <input type="text" name="id" />
    <input type="submit" name="imageShow" />
</form>


</body>
</html>

 

 

imageLoader.php

<?php

if(isset($_GET['id']))
{
    $con = mysql_connect("localhost", "root", "");
    $db = mysql_select_db("image-store", $con);
    $id = $_GET['id'];
    
    $get_query = mysql_query("SELECT * FROM `images` WHERE id = '$id'") or die(mysql_error());
    $get_array = mysql_fetch_array($get_query);
    $image_contents = $get_array['images'];
    
    header('Content-Type: image/gif');
    echo $image_contents;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/179817-solved-database-error/
Share on other sites

Your DATABASE is called image-store. Inside this database there is one TABLE called image-store as well. A FIELD (a.k.a. COLUMN) in this table is called 'images'.

 

So you need to


"INSERT INTO `image-store` (images, ext) VALUES ('$image', '$ext') "
"SELECT * FROM `image-store` WHERE id = '$id'"

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.