Deanznet Posted November 5, 2007 Author Share Posted November 5, 2007 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>"; Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 6, 2007 Share Posted November 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 6, 2007 Author Share Posted November 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 6, 2007 Share Posted November 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 6, 2007 Author Share Posted November 6, 2007 Heyy thanks again.. I keep getting Parse error: parse error, unexpected '{' on line 5.. Not sure why if($_GET['page'] == "viewimage" && !empty($_GET['image_id']){//dose.... Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 6, 2007 Author Share Posted November 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 7, 2007 Author Share Posted November 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 7, 2007 Author Share Posted November 7, 2007 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: Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 Change from: $row = @mysql_fetch_array($query); To: $row = @mysql_fetch_array(mysql_query($query)); Remember, $query is what mysql_query($query) will run, you need this run first :-o Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 7, 2007 Author Share Posted November 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 It looks fine, just post the HTML you're generating when you use it. And we'll see what happens. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 7, 2007 Author Share Posted November 7, 2007 Looks like everything works! Thanks again for all your effort! Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 No problem :-D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.