Displaying a single image and data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hoopy
    New Member
    • Feb 2009
    • 88

    #16
    I think you need to surround the variable if not an int.

    Code:
    $result = mysqli_query($dbLink, 
      "SELECT FileID, FileName, FileMime, 
      FileSize, ToolNumber, Created 
      FROM FileStorage 
      WHERE ToolNumber = 
      '" . mysql_real_escape_string($textfield) . "'");

    Comment

    • mike6256
      New Member
      • Feb 2009
      • 16

      #17
      well I tried:

      '" . mysql_real_esca pe_string($text field) . "'");

      as reccommended- but get:

      There are no files in the database

      PHP Warning: mysql_real_esca pe_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localho st' (using password: NO) in C:\Inetpub\wwwr oot\tlsc\list_f iles.php on line 12 PHP Warning: mysql_real_esca pe_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Inetpub\wwwr oot\tlsc\list_f iles.php on line 12

      Comment

      • hoopy
        New Member
        • Feb 2009
        • 88

        #18
        OK just try the following:

        Code:
        $result = mysqli_query($dbLink, 
          "SELECT FileID, FileName, FileMime, FileSize, 
          ToolNumber, Created 
          FROM FileStorage 
          WHERE ToolNumber = '$textfield'
        ");
        The mysql_real_esca pe_string function is to make the data safe for MySQL insertion, maybe that is not used with mysqli, I have never really used it.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #19
          You're using MySQLi, so mysql_* functions are not going to work. Change it to mysqli_...

          Comment

          • mike6256
            New Member
            • Feb 2009
            • 16

            #20
            Not quite sure I undestand-- can you explain a little and/or give a example?

            Comment

            • hoopy
              New Member
              • Feb 2009
              • 88

              #21
              He means use mysqli_real_esc ape_string() instead of mysql_real_esca pe_string() like so:

              Code:
              $result = mysqli_query($dbLink, 
                "SELECT FileID, FileName, FileMime, 
                FileSize, ToolNumber, Created 
                FROM FileStorage 
                WHERE ToolNumber = 
                '" . mysqli_real_escape_string($textfield) . "'");

              Comment

              • mike6256
                New Member
                • Feb 2009
                • 16

                #22
                Back again--got this error:

                There are no files in the database

                PHP Warning: mysqli_real_esc ape_string() expects exactly 2 parameters, 1 given in C:\Inetpub\wwwr oot\tlsc\list_f iles.php on line 17


                do I need to do something like this

                Code:
                "SELECT FileID, FileName, FileMime,  
                  FileSize, ToolNumber, Created  
                  FROM FileStorage  
                  WHERE id= '$id'
                AND ToolNumber =  
                  '" . mysqli_real_escape_string($textfield) . "'");
                Last edited by Markus; Feb 26 '09, 08:40 PM. Reason: Added [code] tags.

                Comment

                • hoopy
                  New Member
                  • Feb 2009
                  • 88

                  #23
                  Hi,

                  Change:

                  Code:
                  mysqli_real_escape_string($textfield)
                  To:

                  Code:
                  mysqli_real_escape_string($dbLink,$textfield)

                  Comment

                  • mike6256
                    New Member
                    • Feb 2009
                    • 16

                    #24
                    Guess what--more errors

                    PHP Parse error: parse error in C:\Inetpub\wwwr oot\tlsc\list_f iles.php on line 21

                    here are lines 21 thru 70
                    Code:
                    if($result)  
                    { 
                      
                        # Make sure there are some files in there 
                        if(mysqli_num_rows($result) == 0) { 
                            echo "<p>There are no files in the database</p>"; 
                        } 
                        else 
                        { 
                            # Print the top of a table 
                            echo "<table width='100%'><tr>"; 
                            echo "<td><b>Name</b></td>"; 
                            echo "<td><b>Mime</b></td>"; 
                            echo "<td><b>Size (bytes)</b></td>"; 
                            echo "<td><b>Created</b></td>"; 
                    		echo "<td><b>Tool Number</b></td>";
                            echo "<td><b>&nbsp;</b></td>"; 	
                            echo "</tr>"; 
                      
                            # Print each file 
                            while($row = mysqli_fetch_assoc($result)) 
                            { 
                                # Print file info 
                                echo "<tr><td>". $row['FileName']. "</td>"; 
                                echo "<td>". $row['FileMime']. "</td>"; 
                                echo "<td>". $row['FileSize']. "</td>"; 
                                echo "<td>". $row['Created']. "</td>"; 
                    			echo "<td>". $row['ToolNumber']. "</td>";
                      
                                # Print download link 
                                echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download</a></td>"; 
                                echo "</tr>"; 
                            } 
                      
                            # Close table 
                            echo "</table>"; 
                        } 
                      
                        # Free the result 
                        mysqli_free_result($result); 
                    } 
                    else  
                    { 
                        echo "Error! SQL query failed:"; 
                        echo "<pre>". $dbLink->error ."</pre>"; 
                    } 
                      
                    # Close the mysql connection 
                    mysqli_close($dbLink); 
                    ?>
                    Last edited by Markus; Feb 26 '09, 08:51 PM. Reason: Added [code] tags.

                    Comment

                    • hoopy
                      New Member
                      • Feb 2009
                      • 88

                      #25
                      I suspect the error is just prior to what you pasted.

                      Please post all the code and use code tags as well please. Its very difficult to read without tags.

                      Comment

                      • Markus
                        Recognized Expert Expert
                        • Jun 2007
                        • 6092

                        #26
                        mike,

                        Please read your Personal Messages. You have already received a warning.

                        Comment

                        • mike6256
                          New Member
                          • Feb 2009
                          • 16

                          #27
                          how do I do code tags??

                          Comment

                          • mike6256
                            New Member
                            • Feb 2009
                            • 16

                            #28
                            sorry about the tags

                            here is the code--let me know if I did it correct

                            Code:
                             <?php 
                            # Connect to the database 
                            $dbLink = mysqli_connect("71.39.54.10", "root", "trinidad", "tools"); 
                            if(mysqli_connect_errno()) { 
                                die("MySQL connection failed: ". mysqli_connect_error()); 
                            } 
                              
                            # Query for a list of all existing files 
                            // just one possibility... 
                            $textfield = $_POST['textfield'];  
                              
                            $result = mysqli_query($dbLink,  
                              "SELECT FileID, FileName, FileMime,  
                              FileSize, ToolNumber, Created  
                              FROM FileStorage  
                              WHERE ToolNumber =  
                              '" . mysqli_real_escape_string($dbLink,$textfield) 
                             
                              
                            # Check if it was successfull 
                            if($result)  
                            { 
                              
                                # Make sure there are some files in there 
                                if(mysqli_num_rows($result) == 0) { 
                                    echo "<p>There are no files in the database</p>"; 
                                } 
                                else 
                                { 
                                    # Print the top of a table 
                                    echo "<table width='100%'><tr>"; 
                                    echo "<td><b>Name</b></td>"; 
                                    echo "<td><b>Mime</b></td>"; 
                                    echo "<td><b>Size (bytes)</b></td>"; 
                                    echo "<td><b>Created</b></td>"; 
                            		echo "<td><b>Tool Number</b></td>";
                                    echo "<td><b>&nbsp;</b></td>"; 	
                                    echo "</tr>"; 
                              
                                    # Print each file 
                                    while($row = mysqli_fetch_assoc($result)) 
                                    { 
                                        # Print file info 
                                        echo "<tr><td>". $row['FileName']. "</td>"; 
                                        echo "<td>". $row['FileMime']. "</td>"; 
                                        echo "<td>". $row['FileSize']. "</td>"; 
                                        echo "<td>". $row['Created']. "</td>"; 
                            			echo "<td>". $row['ToolNumber']. "</td>";
                              
                                        # Print download link 
                                        echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download</a></td>"; 
                                        echo "</tr>"; 
                                    } 
                              
                                    # Close table 
                                    echo "</table>"; 
                                } 
                              
                                # Free the result 
                                mysqli_free_result($result); 
                            } 
                            else  
                            { 
                                echo "Error! SQL query failed:"; 
                                echo "<pre>". $dbLink->error ."</pre>"; 
                            } 
                              
                            # Close the mysql connection 
                            mysqli_close($dbLink); 
                            ?>

                            Comment

                            • Markus
                              Recognized Expert Expert
                              • Jun 2007
                              • 6092

                              #29
                              You've missed some quotes:
                              Code:
                              $result = mysqli_query($dbLink,  
                                "SELECT FileID, FileName, FileMime,  
                                FileSize, ToolNumber, Created  
                                FROM FileStorage  
                                WHERE ToolNumber =  
                                '" . mysqli_real_escape_string($dbLink,$textfield)
                              Should be

                              Code:
                              $result = mysqli_query($dbLink,  
                                "SELECT FileID, FileName, FileMime,  
                                FileSize, ToolNumber, Created  
                                FROM FileStorage  
                                WHERE ToolNumber =  
                                '" . mysqli_real_escape_string($dbLink,$textfield) . "'";

                              Comment

                              • mike6256
                                New Member
                                • Feb 2009
                                • 16

                                #30
                                added the quotes--now get:
                                PHP Parse error: parse error in C:\Inetpub\wwwr oot\tlsc\list_f iles.php on line 17 here are lines 12 - 17
                                Code:
                                $result = mysqli_query($dbLink,   
                                  "SELECT FileID, FileName, FileMime,   
                                  FileSize, ToolNumber, Created   
                                  FROM FileStorage   
                                  WHERE ToolNumber =   
                                  '" . mysqli_real_escape_string($dbLink,$textfield) . "'";

                                Comment

                                Working...