PHP script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matheussousuke
    New Member
    • Sep 2009
    • 249

    PHP script

    May someone help me correct this script? there a few ' and " and ; in the wrong places:


    Code:
    <?php
    include "./comm.inc"; 
    connectdb(); 
    $sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";  
    
    $result = @mysql_query($sql) or die(mysql_error());  
    
    echo '<table border=1>n';  
    echo '<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>n';  
    while ($rs=mysql_fetch_array($result)) {  
      echo '<tr><td>.$rs[0].</td>';  
      echo '<td>.$rs[1].</td>';  
      echo '<td><img src="post.php?imgid=.$rs[0]."" width=100 height=100></td></tr>n';  
    echo '</table>n';  
    
    ?>
  • matheussousuke
    New Member
    • Sep 2009
    • 249

    #2
    I'll post here the other two codes:

    post.php -->

    Code:
    <?  
    if (!isset($submit)) {  
    ?>  
    <form method="POST" action="" enctype=multipart/form-data>  
    <table>  
    <tr><td>Type</td><td><select name="imgtype"><option value="image/gif">GIF</option><option  
    value="image/jpeg">JPEG</option></select></td></tr>  
    <tr><td>File</td><td><input type="file" name="imgfile"></td></tr>  
    <tr><td></td><td><input type="submit" name="submit" value="upload"><input type="reset" value="reset"></td></tr>  
    </table>  
    </form>  
    <?  
    } else {  
            include "./comm.inc"; 
            connectdb(); 
            $hndl=fopen($imgfile,"rb");  
            $imgdata=''; 
            while(!feof($hndl)){ 
                    $imgdata.=fread($hndl,2048);  
            } 
    
    {
            $imgdata=addslashes($imgdata);  
    
            $sql = 'INSERT INTO tblimage VALUES(NULL,". $imgtype .",". $imgdata .")';  
    
            @mysql_query($sql) or die(mysql_error());  
    
            fclose($hndl);  
    
            echo '<a href="view.php">view image</a>';  
    }  
    ?>


    And




    upload.php -->





    Code:
    <?php
    if (!isset($submit)) {
    ?>
    <form method="POST" action="" enctype=multipart/form-data>
    <table>
    <tr><td>Tipo</td><td><select name="imgtype"><option value="image/gif">GIF</option><option
    value="image/jpeg">JPEG</option></select></td></tr>
    <tr><td>File</td><td><input type="file" name="imgfile"></td></tr>
    <tr><td></td><td><input type="submit" name="submit" value="upload"><input type="reset" value="reset"></td></tr>
    </table>
    </form>
    <?
    } else {
            include "./comm.inc";
            connectdb();
            $hndl=fopen($imgfile,"rb");
            $imgdata='';
            while(!feof($hndl)){
                    $imgdata.=fread($hndl,2048);
            }
    
            $imgdata=addslashes($imgdata);
    
            $sql = 'INSERT INTO tblimage VALUES(NULL,", $imgtype .",". $imgdata .")';
    
            @mysql_query($sql) or die(mysql_error());
    
            fclose($hndl);
            echo '<a href="view.php">view image</a>';
    }
    ?>

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      This is a rather tiresome task you have set.
      Do you think it is fair to expect people to trail through your code looking for syntax errors.
      If you put some debugging in your code you might help yourself to find the problem

      Comment

      • matheussousuke
        New Member
        • Sep 2009
        • 249

        #4
        sorry, I just though....

        Comment

        • matheussousuke
          New Member
          • Sep 2009
          • 249

          #5
          whell, I fexed a little things in view.php, and upload.php is correct, maybe the trouble is just in post, and dont get any error using the scripts, that's the problem but the image doesnt appear when I open view.php

          Comment

          • matheussousuke
            New Member
            • Sep 2009
            • 249

            #6
            I'll post a photo here

            Comment

            • matheussousuke
              New Member
              • Sep 2009
              • 249

              #7
              This is how it appears on the browser:






              And this is how I left view.php:


              Code:
              <?php
              include "./comm.inc"; 
              connectdb(); 
              $sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";  
              
              $result = @mysql_query($sql) or die(mysql_error());  
              {
              echo '<table border=1>n';  
              echo '<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>n';  
              while ($rs=mysql_fetch_array($result))
              
                echo '<tr><td>".$rs[0]."</td>';  
                echo '<td>".$rs[1]."</td>';  
                echo '<td><img src="post.php?imgid=.$rs[0]." width=100 height=100></td></tr>n';  
              echo '</table>n';
              
              
              }
              
              ?>

              Comment

              • matheussousuke
                New Member
                • Sep 2009
                • 249

                #8
                True is I'm not getting any bug anymore, but, it just doesn't appears.

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Variables are not parsed within single quoted strings. You'll have to concatenate the string or use double quotes:

                  Code:
                  $name = "Mark";
                  // Works
                  echo "My name is $name";
                  // Also works
                  echo 'My name is ' . $name;
                  // Doesn't work: prints "My name is $name"
                  echo 'My name is $name';
                  Also, in future please provide all error details. Simply asking us to 'look at' something and deduce what is wrong with it simply isn't the proper way to ask a question to a bunch of volunteers.

                  Mark.

                  Comment

                  • matheussousuke
                    New Member
                    • Sep 2009
                    • 249

                    #10
                    Originally posted by Markus
                    Variables are not parsed within single quoted strings. You'll have to concatenate the string or use double quotes:

                    Code:
                    $name = "Mark";
                    // Works
                    echo "My name is $name";
                    // Also works
                    echo 'My name is ' . $name;
                    // Doesn't work: prints "My name is $name"
                    echo 'My name is $name';
                    Also, in future please provide all error details. Simply asking us to 'look at' something and deduce what is wrong with it simply isn't the proper way to ask a question to a bunch of volunteers.

                    Mark.


                    Do I have to do that to view.php, post.php, upload.php, or both?

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      Originally posted by matheussousuke
                      Do I have to do that to view.php, post.php, upload.php, or both?
                      Wherever you are outputting strings (and they are not showing correctly).

                      Comment

                      • matheussousuke
                        New Member
                        • Sep 2009
                        • 249

                        #12
                        Well, true is, I found that script on forum, dont remember witch, had to correct a lot of things, it was worst than that.


                        Let's go to the point, all I wanted was a simple script that could upload a image to mysql and show it on page. And this script "does" all of this.


                        So if someone could give a script with that simple task, I would be really greatful, I'm not being rude, I'm tellgin that cause I spent more than 4 hours looking on google for a script that could do what I need.

                        The goal is put a option on my site where the user can be able to manage the index logo diretly from the admin area by using image upload function.

                        Comment

                        • code green
                          Recognized Expert Top Contributor
                          • Mar 2007
                          • 1726

                          #13
                          What Markus is referring to is lines such as this
                          Code:
                          echo '<td><img src="post.php?imgid=.$rs[0]." 
                          width=100 height=100></td></tr>n';
                          You have wrapped the whole line in single quotes so the variable inside will not be parsed.
                          In fact the variable is concatenated but the quotes are not opened or closed
                          This is better
                          Code:
                          echo '<td><img src="post.php?imgid='.$rs[0].'" 
                          width=100 height=100></td></tr>n';
                          You need to correct all lines such as this

                          Comment

                          • matheussousuke
                            New Member
                            • Sep 2009
                            • 249

                            #14
                            Image upload

                            I'm using a image upload script without mysql, it works perfectly, all I want is to show its image on my site index.

                            The script works like this:

                            It simple upload a image with the name logo. with extension in front (eg. logo.png).

                            What I need is a way to show it on index with a code such as img src


                            eg.:

                            Code:
                            <?
                            echo '<img src="admin/fotos/logo.   I need a way to put a extension variable here, so, undepeding on extension format, it will always show image file, rembering that the name is aways "logo.".
                            
                            ">';
                            ?>

                            Comment

                            • code green
                              Recognized Expert Top Contributor
                              • Mar 2007
                              • 1726

                              #15
                              It has been explained to you what you are doing wrong in your thread http://bytes.com/topic/php/answers/876650-php-script

                              Comment

                              Working...