Jump to content

[SOLVED] Php Search Mysql.. and displaying.


Deanznet

Recommended Posts

Hey did you get my pms?

 

 

Also can you explain these part do.

 



if(is_numeric($_GET['image_id']) && $_GET['page'] == "viewimage"){//dose that make it do image_id= the image 

$image_id = mysql_real_escape_string($_GET['image_id']);//make it sanitized for database input

    $query = "SELECT filename,pkey,basename FROM images where image_id = '$image_id' LIMIT 1";
if(!mysql_num_rows($query)){//this returned 0, so die
die("I'm sorry, we cannot find the image in the database."); -- selects the filename,pkey,basename from images colume
}

$row = mysql_fetch_array($query);
echo "<img src=".$row['basename']." alt=".$row['filename']."><br>"; - displays them?
echo "<b>Viewing image: ".$row['pkey']."</b>";


Link to comment
Share on other sites

This is the same code, just a few minor changes to actually display something... It checks to see if you put in an image_id, that it in fact is a number, sanitizes this number (just in case of sql injection), grabs the image details off the database and displays it.

Link to comment
Share on other sites

Okay...

 

The image_id is also letters to... 24sdfh1d21n looks like that sometimes.

 

When i use that code it dosent display any images..

 

or any information.. just ...

 

Show something else here, we're not looking at a specific image...

 

Also if you put a made up id in it still works...

 

basicly all i want it do to.. is grab the id from the url

 

so if some puts 7dasnf7as it searches image column and the filename table.. if it finds the exact match it will echo out the image on the page witch is located in the basename table and than after that some room for my other stuff

 

Link to comment
Share on other sites

Oh, then we can't use just numeric O_O

 

if($_GET['page'] == "viewimage" && !empty($_GET['image_id']){//dose that make it do image_id= the image 

$image_id = mysql_real_escape_string($_GET['image_id']);//make it sanitized for database input

    $query = "SELECT filename,pkey,basename FROM images where image_id = '$image_id' LIMIT 1";
if(!mysql_num_rows($query)){//this returned 0, so die
die("I'm sorry, we cannot find the image in the database.");//selects the filename,pkey,basename from images colume
}

$row = mysql_fetch_array($query);
echo "<img src=".$row['basename']." alt=".$row['filename']."><br>";//displays the images
echo "<b>Viewing image: ".$row['pkey']."</b>";

 

Try that, what it does is if we're on ?page=viewimage, we check to see if image_id is not empty, if it is not empty, we'll run through this whole thing... If there is no image_id in the database, we'll do a die error.

 

Make sure you use double // for commenting out lines

Link to comment
Share on other sites

Fixed the error i was getting befor

 

if($_GET['page'] == "viewimage" && !empty($_GET['image_id']))

 

Added the extra ) at the end seemed to fix it..

 

But now i get a new error..

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in line 9..

 

and that is

 

if(!mysql_num_rows($query)){//this returned 0, so die

 

Also

 

if i go to

 

http://www.mysite.net/image.php?page=viewimage&image_id=aec448645c

 

The aec448645c  should be in the pkey table so it should find it but it says

 

I'm sorry, we cannot find the image in the database.

 

Link to comment
Share on other sites

Double check the query to make sure that it's formatted correctly.

 

$query = "SELECT filename,pkey,basename FROM images where image_id = '$image_id' LIMIT 1";

 

Also, it's not:

if(!mysql_num_rows($query)){//this returned 0, so die

 

It's:

 

if(!mysql_num_rows(mysql_query($query))){//this returned 0, so die

Link to comment
Share on other sites

Alright! now it reads the url..

 

But i keep getting

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

 

and it shows a broken image when you go to the page.. so i dont think its pulling the information from the database.

Link to comment
Share on other sites

I added an @ infront so i think that fixed the error message but still wont pull the information from that database..

 

 

 

<?
include("include/common.php");
if($_GET['page'] == "viewimage" && !empty($_GET['image_id']))//dose that make it do image_id= the image 

$image_id = mysql_real_escape_string($_GET['image_id']);//make it sanitized for database input

$query = "SELECT filename,id,pkey,basename,keywords FROM images where id = '$image_id' LIMIT 1";
if(!@mysql_num_rows(mysql_query($query))){
die("I'm sorry, we cannot find the image in the database.");//selects the filename,pkey,basename from images colume
}

$row = @mysql_fetch_array($query);
echo "<img src=".$row['basename']." alt=".$row['filename']."><br>";//displays the images
echo "<b>Viewing image: ".$row['pkey']."</b>";

?>

 

I dont see why not..

 

It dose not display the filename or pkey or basename on the page..

 

Just has Broken image than under that is Viewing image:

 

 

Link to comment
Share on other sites

Well i got the image to display using this code i fixed

 

 

<?
include("include/common.php");
if($_GET['page'] == "viewimage" && !empty($_GET['image_id']))
$image_id = mysql_real_escape_string($_GET['image_id']);
$query = @mysql_query("SELECT id,keywords,basename FROM images where id = '$image_id' LIMIT 1");

if(!mysql_num_rows($query)){//0 = false, 1 or more = true
die("I'm sorry, no results were found for $keyword_query.");
}

$row = @mysql_fetch_array($query);
echo "<img src=".$row['basename']." alt=".$row['filename']."><br>";
echo "<b>Viewing image: ".$row['pkey']."</b>";


?>

 

didn't use $row = @mysql_fetch_array(mysql_query($query));

 

it that a problem?

 

But keywords and filename still wont show

 

 

Link to comment
Share on other sites

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.