Results 1 to 10 of 10

Thread: problem with this code

  1. #1
    Join Date
    Oct 2008
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default problem with this code

    PHP Code:
    <?php

    $host 
    "host"
    $user "user"
    $pass "password"


    $con mysql_connect($host $user ,  $pass);
       
    if(!
    $con)

      die(
    "Failed to connect to the server" mysql_error());
    }

    $image "images/advert.jpg";

    $result mysql_query("SELECT * FROM table WHERE image = $image");
    while(
    $row mysql_fetch_array($result))
    {
    echo  
    $row['image'];
    ?>

    I created in database a table ''image" and i created in this table a decimal camp called 'image'. I put the image advert.jpg in image folder but it doesnt works.

    It appears to me this message:
    Parse error: syntax error, unexpected $end in /home/hosting/masterfifa/index.php on line 25
    Last edited by Snookerman; 04-14-2010 at 09:56 AM. Reason: please use [php] tags for php code

  2. #2
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    <?php
    $host 
    "host";
    $user "user";
    $pass "password";
    $link mysql_connect($host $user $pass);
    if(
    $link)
    {
          
    $db_selected mysql_select_db("databasename",$link);
          if (
    $db_selected)
          {
                  
    $image "images/advert.jpg";
                  
    $result mysql_query("SELECT * FROM table WHERE image='".$image."'");
                   while(
    $I mysql_fetch_array($result))
                   {
                          echo 
    "- entry: ".$I['image']."<br/>";
                  }
           }
    }
    ?>
    expected
    - entry: images/advert.jpg <br/>
    repeated the number of times in the database

    changes:
    added database select
    changed some names ^_^
    updated the SQL to enclose the WHERE statment value in '
    finished teh code

  3. #3
    Join Date
    Oct 2008
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by zeromadpeter View Post
    PHP Code:
    <?php
    $host 
    "host";
    $user "user";
    $pass "password";
    $link mysql_connect($host $user $pass);
    if(
    $link)
    {
          
    $db_selected mysql_select_db("databasename",$link);
          if (
    $db_selected)
          {
                  
    $image "images/advert.jpg";
                  
    $result mysql_query("SELECT * FROM table WHERE image='".$image."'");
                   while(
    $I mysql_fetch_array($result))
                   {
                          echo 
    "- entry: ".$I['image']."<br/>";
                  }
           }
    }
    ?>
    expected
    - entry: images/advert.jpg <br/>
    repeated the number of times in the database

    changes:
    added database select
    changed some names ^_^
    updated the SQL to enclose the WHERE statment value in '
    finished teh code
    the code you gave me is ok, it doesn' appears to me any error but it doesn't apears the photo, which is the thing that i want for this code to do. Please help me with this code to appears me the photo. Thanks

  4. #4
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    if you want it to output the html for the image then why are u using a database and not just

    <img src="./images/advert.jpg" alt="image woot"/>

    please can you tell me what you want to do with the database.

  5. #5
    Join Date
    Oct 2008
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by zeromadpeter View Post
    if you want it to output the html for the image then why are u using a database and not just

    <img src="./images/advert.jpg" alt="image woot"/>

    please can you tell me what you want to do with the database.
    because I am a beginner in php and I want to learn to do in php things that I can make in html, so can you tell me in php how I do that the image appears?

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    PHP Code:
    while($I mysql_fetch_array($result))
                   {
                          
    $img sprintf("<img src=\"%s\" width=\"\" height=\"\" alt=\"\">"$I['image']);
                          echo 
    $img;
                  } 

  7. #7
    Join Date
    Oct 2008
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    now I have this code:

    <?php
    $host = "host";
    $user = "user";
    $pass = "password";
    $link = mysql_connect($host , $user , $pass);
    if($link)
    {
    $db_selected = mysql_select_db("image",$link);
    if ($db_selected)
    {
    $image = "images/advert.jpg";
    $result = mysql_query("SELECT * FROM table WHERE image='".$image."'");
    while($I = mysql_fetch_array($result))
    {
    echo "- entry: ".$I['image']."<br/>";
    }
    }
    }
    while($I = mysql_fetch_array($result))
    {
    $image = sprintf("<img src="images/advert.jpg" width="20" height="100" alt="20">", $I['image']);
    echo $img;
    }
    ?>


    and this don't works too, It appears to me this message:

    Parse error: syntax error, unexpected T_STRING in /home/hosting/masterfifa/index.php on line 21

  8. #8
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    here try this.
    PHP Code:
    <?php
    $host 
    "host";
    $user "user";
    $pass "password";
    $link mysql_connect($host $user $pass);

    if(
    $link) {
        
    $db_selected mysql_select_db("image",$link);
        if (
    $db_selected) {
            
    $image "images/advert.jpg";
            
    $result mysql_query("SELECT * FROM table WHERE image='$image' ");
            while(
    $I mysql_fetch_array($result)) {
                echo 
    "- entry: ".$I['image']."<br/>";
            }
        }
    }

    while(
    $I mysql_fetch_array($result)) {
        
    $img sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">"$I['image']);
        echo 
    $img;

                      
    ?>
    If you look at this specific line

    PHP Code:
    $img sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">"$I['image']); 
    The backslashes in font of the quotes are needed to tell php to ignore this quote as the end of the string I'm entering. I believe the proper name for it is escaping.

    Just remember that any time you need to use a quote for a normal html like src="", alt="", etc. inside your php echo string or whatever else your entering you need to add the backslash in front of it so php will ignore the quote.

  9. #9
    Join Date
    Oct 2008
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by punstc View Post
    here try this.
    PHP Code:
    <?php
    $host 
    "host";
    $user "user";
    $pass "password";
    $link mysql_connect($host $user $pass);

    if(
    $link) {
        
    $db_selected mysql_select_db("image",$link);
        if (
    $db_selected) {
            
    $image "images/advert.jpg";
            
    $result mysql_query("SELECT * FROM table WHERE image='$image' ");
            while(
    $I mysql_fetch_array($result)) {
                echo 
    "- entry: ".$I['image']."<br/>";
            }
        }
    }

    while(
    $I mysql_fetch_array($result)) {
        
    $img sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">"$I['image']);
        echo 
    $img;

                      
    ?>
    If you look at this specific line

    PHP Code:
    $img sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">"$I['image']); 
    The backslashes in font of the quotes are needed to tell php to ignore this quote as the end of the string I'm entering. I believe the proper name for it is escaping.

    Just remember that any time you need to use a quote for a normal html like src="", alt="", etc. inside your php echo string or whatever else your entering you need to add the backslash in front of it so php will ignore the quote.
    I tried this code and it doesn't appears me any message error, but it doesn't apeears image too. Look here http://masterfifa.3x.ro, here should appears the advert.jpg photo.

  10. #10
    Join Date
    Oct 2008
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I still can't see the photo.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •