Help...with imgview.php

Discussion in 'PHP' started by Alibaba143, Dec 9, 2012.

  1. #1
    Here is my code...

    index.php

    <?php    
        include('config.php');
        echo"<div class='imageRow'>
          <div class='set'>";
        $query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC;");
    while($row = mysql_fetch_array($result))
    {
           echo '<div class="single"><div class="wrap">
         <div class="details">
         <div class="views">
    <a href="viewingimg.php?id=" '.$row['image'].'" title="'.$row['caption'].'"><img src="'.$row['image'].'" /></a>' . $row['details'] . '
    </div></div></div></div>';
    }                
    ?>
    Code (markup):
    imgview.php

     <?php
    
    include('config.php');
    
    
    $id = $_GET['id'];
    
    
    if(!isset($id) || empty($id) || !is_int($id)){
             die("Please select your image!");
    }else{
    
    
    $query = mysql_query("SELECT * FROM photos WHERE id='".$id."'");
    $row = mysql_fetch_array($query);
    $content = $row['image'];
    
    
    header('Content-type: image/jpg');
             echo $content;
    }
    ?>
    Code (markup):
    But when i click on the image is gives error PLEASE SELECT YOUR IMAGE....can anyone help me where i m wrong :p .. Thanks
     
    Alibaba143, Dec 9, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    
    while($row = mysql_fetch_array($result)) {
           [COLOR=#ff0000] //[/COLOR]echo '<div class="single"><div class="wrap">      <div class="details">      <div class="views"> <a href="viewingimg.php?id=" '.$row['image'].'" title="'.$row['caption'].'"><img src="'.$row['image'].'" /></a>' . $row['details'] . '
    [COLOR=#ff0000]
    echo 'id="'.$row['image'].'"';[/COLOR]
     
    Code (markup):
    Then you'll see what data you're sending to imageview.php You seem to be sending the file name as the id. Maybe you meant $row['id']?
     
    Rukbat, Dec 9, 2012 IP
  3. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <?php
    	
    	include('config.php');
        echo"<div class='imageRow'>
      	<div class='set'>";
    	$query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC;");
    while($row = mysql_fetch_array($result)) {
            echo '<div class="single"><div class="wrap">      <div class="details">      <div class="views"> <a href="viewingimg.php?id=" '.$row['image'].'" title="'.$row['caption'].'"><img src="'.$row['image'].'" /></a>' . $row['details'] . '
    
    
    echo 'id="'.$row['image'].'"';
    
    
    </div></div></div></div>';
    }				
    ?>
    Code (markup):
    Error

    Parse error: syntax error, unexpected 'id' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\test\index.php on line 44
     
    Alibaba143, Dec 10, 2012 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    This script is realy weird, te script referers to viewingimg.php but you show code for imgview.php

    ? does the script exists? try to open the 'not visable' image into a new screen and then check the URL!
     
    EricBruggema, Dec 10, 2012 IP
  5. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    .

    my page is saved as viewingimg.php ... in this forum i just mentioned imgview by mistake, sorry for that, i m just a newbie, trying to learn and do something with php, just need help
     
    Alibaba143, Dec 10, 2012 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    
    <?php
        
        include('config.php');
        echo"<div class='imageRow'>
          <div class='set'>";
        $query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC;");
    while($row = mysql_fetch_array($result)) {
            echo '<div class="single"><div class="wrap">      <div class="details">      <div class="views"> <a href="viewingimg.php?id=" '.$row['image'].'" title="'.$row['caption'].'"><img src="'.$row['image'].'" /></a>' . $row['details'] . '
    
    
    echo 'id="'.$row['image'].'"';
    
    
    [COLOR=#ff0000]echo '[/COLOR]</div></div></div></div>';
    }                
    ?>
    Code (markup):
    I left off the bottom of the code. Sorry.
     
    Rukbat, Dec 10, 2012 IP
  7. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #7
    the problem come from this code
    <a href="viewingimg.php?id="  '.$row['image'].'" title="'.$row['caption'].'"><img  src="'.$row['image'].'" /></a>'
    PHP:
    this code will produce html like this
    <a href="viewingimg.php?id=" filename.ext" title="any title"><img src="filename.ext" /></a>
    HTML:
    you can check its html source from your browser.
    this is a wrong link tags, so query id always empty.

    try to remove quote and space behind id= like this
    <a  href="viewingimg.php?id='.$row['image'].'"  title="'.$row['caption'].'"><img src="'.$row['image'].'"  /></a>'
    PHP:
     
    ogah, Dec 10, 2012 IP
  8. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks for ur replies, but it still doesn't work, problem is here
    viewingimg.php
    <?php
    
    include('config.php');
    
    
    $id = $_GET['id'];
    
    
    if(!isset($id) || empty($id) || !is_int($id)){
             die("Please select your image!");
    }else{
    
    
    $query = mysql_query("SELECT * FROM photos WHERE id='".$id."'");
    $row = mysql_fetch_array($query);
    $content = $row['image'];
    
    
    header('Content-type: image/jpg');
             echo $content;
    }
    ?>
    Code (markup):
    Error Msg

    Notice: Undefined index: id in C:\xampp\htdocs\test\viewingimg.php on line 37
    Please select your image!

    Line 37 =
    $id = $_GET['id'];
     
    Alibaba143, Dec 11, 2012 IP
  9. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #9
    That's because there's no element in the form on the page with a name of id. The GET variables come from the HTML form, they're the names of the elements (textboxes, etc.) in the form. You have to have a textbox or dropdown or something named id (as in name="id"). In your case it will probably be an array of checkboxes named id. Or an array of checkboxes with different names, and your PHP code sees which one is checked and makes $id the name of that checkbox (or whatever calue you need it to be to find the picture in the database).
     
    Rukbat, Dec 11, 2012 IP
  10. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #10
    @Alibaba143 problem come from your index.php not in your viewingimg.php please edit first your index.php like i said.
    @Rukbat he have, look at his index.php he have query id with wrong link tag. so he always get url http://localhost/test/viewingimg.php?id=
    the url always ended with id= without query value so $_GET['id'] always have empty value.
    it must http://localhost/test/viewingimg.php?id=file.jpg
    like you type url http://www.google.com/search?q= what you'll get with url like that?
     
    Last edited: Dec 11, 2012
    ogah, Dec 11, 2012 IP
  11. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I have done the same u said, but it gives syntax error

    Parse error: syntax error, unexpected 'id' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\test\index.php on line45

    Line 45 =
    echo 'id="'.$row['image'].'"';
     
    Alibaba143, Dec 13, 2012 IP
  12. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #12
    I can't be sure without seeing more code, but make sure line 44 ends with a ;

    And make sure that's line 45. There doesn't seem to be anything wrong with it.
     
    Rukbat, Dec 13, 2012 IP
  13. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    here is the whole code
    <?php    
        include('config.php');
        echo"<div class='imageRow'>
          <div class='set'>";
        $query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC;");
    while($row = mysql_fetch_array($result)) {
            echo '<div class="single"><div class="wrap">      <div class="details">      <div class="views"> <a href="viewingimg.php?id=" '.$row['image'].'" title="'.$row['caption'].'"><img src="'.$row['image'].'" /></a>' . $row['details'] . '
    
    
    
    
    echo 'id="'.$row['image'].'"';
    
    
    
    
    echo '</div></div></div></div>';
    }                
    ?>
    Code (markup):
    error is

    Parse error: syntax error, unexpected 'id' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\test\index.php on line45

    Line 45 =
    echo 'id="'.$row['image'].'"';
     
    Alibaba143, Dec 13, 2012 IP
  14. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #14
    Free help :)

    
    <?php    
        include('config.php');
        echo"<div class='imageRow'>
          <div class='set'>";
        $query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC;");
    while($row = mysql_fetch_array($result)) {
            echo '<div class="single"><div class="wrap">      <div class="details">      <div class="views"> <a href="viewingimg.php?id=" '.$row['image'].'" title="'.$row['caption'].'"><img src="'.$row['image'].'" /></a>' . $row['details'];
    
    echo 'id="'.$row['image'].'"';
    
    echo '</div></div></div></div>';
    }
    ?>
    
    Code (markup):
    that should work...
     
    EricBruggema, Dec 14, 2012 IP
  15. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Thanks EricBruggema

    but now it shows id with the pic details, like pic name is funny, it shows like ... funnyid="photos/funny... and the url is ... localhost/test/viewingimg.php?id=
    its not getting pic id and displaying the pic
     
    Alibaba143, Dec 14, 2012 IP
  16. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #16
    you not read my post? capek deh...
     
    ogah, Dec 14, 2012 IP
  17. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #17
    
    <?php    
        include('config.php');
        echo"<div class='imageRow'>
          <div class='set'>";
        $query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC;");
    while($row = mysql_fetch_array($result))
    {
           echo '<div class="single"><div class="wrap">
         <div class="details">
         <div class="views">
    <a href="viewingimg.php?id='.$row['image'].'" title="'.$row['caption'].'"><img src="'.$row['image'].'" /></a>' . $row['details'] . '
    </div></div></div></div>';
    }                
    ?>
    
    PHP:
     
    ogah, Dec 14, 2012 IP
  18. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Thanks ogah, i read ur post...but it doesn't show pic...when i click on the image, it gives the link like http://localhost/test/viewingimg.php?id=file.jpg
    but not showing pic. it give the msg Please Select Your Image.
     
    Alibaba143, Dec 14, 2012 IP
  19. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #19
    your index.php showing the image or not?
    if your index.php showing image, try edit viewingimg.php remove || !is_int($id)
     
    ogah, Dec 14, 2012 IP
  20. johnmalkin

    johnmalkin Greenhorn

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #20
    rather then doing new coding, i suggest to use timthumb for this. its easy and customized coding.
     
    johnmalkin, Dec 14, 2012 IP