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>"; Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-385007 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. Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-385376 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 Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-385434 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 Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-385642 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.... Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-385694 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. Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386034 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 Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386272 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. Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386306 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: Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386310 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 Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386386 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 Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386392 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. Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386398 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! Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386407 Share on other sites More sharing options...
kratsg Posted November 7, 2007 Share Posted November 7, 2007 No problem :-D Link to comment https://forums.phpfreaks.com/topic/75866-solved-php-search-mysql-and-displaying/page/2/#findComment-386409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.