By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,990 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,990 IT Pros & Developers. It's quick & easy.

help for broken link

P: 9
Hi, i been working on this codes but i keep getting broken links for the pictures.
Im using apache.
Need help for this please.
I think its just the codes in my index.php is wrong and i do not know what is the solution.

Code for my addstar.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $HOST = 'localhost';
  3. $USERNAME = 'root';
  4. $PASSWORD = '';
  5. $DB = 'c203';
  6.  
  7. $link = mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB) or die(mysqli_connect_error());
  8. $sql = "SELECT name,birthday,nationality,age,biography,picture FROM stars";
  9. $result = mysqli_query($link, $sql) or die(mysqli_error($link));
  10. ?>
  11. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  12. <html>
  13.     <head>
  14.         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  15.         <title>StarGazer</title>
  16.     </head>
  17.     <body>
  18.         <h1>StarGazer</h1>
  19.         <hr />
  20.         <h2>Welcome</h2>
  21.         <table border='1' cellpadding='0' cellspacing='0'>
  22. <?php
  23.     while($row=mysqli_fetch_assoc($result)){
  24.         echo "<tr>";
  25.         echo "<td>".$row['picture']."</td>";  
  26.         echo "<img src='picture/" ;
  27.         echo "</tr>";    
  28.  
  29.  
  30.         //use $row and IMG SRC
  31.     }
  32.  
  33.  
  34.  
  35. ?>        
  36.         </table>
  37.     </body>
  38. </html>
Codes for my index.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // find the code that only do INSERT
  3. $name = $_POST['name'];
  4. $birthday = $_POST['birthday'];
  5. $nationality = $_POST['nationality'];
  6. $age = $_POST['age'];
  7. $biography = $_POST['biography'];
  8.  
  9.     $target_path = "uploads/";
  10.     $target_path = $target_path . basename( $_FILES['upfile']['name']); 
  11.     if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path . basename ( $_FILES['upfile']['name']))) {
  12.         echo "The file ".  basename( $_FILES['upfile']['name']). " has been uploaded. Please click <a href=index.php>here </a> ";
  13.     }
  14.     else{
  15.     echo "There was an error uploading the file, please try again!";
  16.         }
  17.  
  18.  
  19.     $host = 'localhost';
  20.     $username = 'root';
  21.     $password = '';
  22.     $db = 'c203';
  23.  
  24.     $link = mysqli_connect($host,$username,$password,$db);{
  25.     $query = "INSERT INTO stars(name,birthday, nationality,age,biography,picture) 
  26.     VALUES('$name','$birthday','$nationality','$age','$biography','$target_path')";
  27.     $result = mysqli_query($link, $query) or die(mysqli_error($link));
  28.         }     
  29.  
  30.     $message = "Name : " . $name . "<br />";
  31.     $message1 = "Birthday : " . $birthday . "<br />";
  32.     $message2 = "Nationality : " . $nationality . "<br />";
  33.     $message3 = "Age : " . $age. "<br />";
  34.     $message4 = "Biography : " . $biography . "<br />";
  35.  
  36.  
  37.  
  38.  
  39. ?>
Jan 5 '10 #1
Share this Question
Share on Google+
8 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Are you retrieving a picture from the database or are you retrieving the path/url to the picture from the database?

In your addstar.php, on line 26 you need to add a ">" to close the img HTML tag.
It should be:
Expand|Select|Wrap|Line Numbers
  1. echo "<img src='picture' />" ;
Or if you are retrieving the url to the picture from the database...it should be:
Expand|Select|Wrap|Line Numbers
  1. echo "<img src='".$row['picture']."' />" ;
-Frinny
Jan 5 '10 #2

P: 9
Hi Frinny, tks for the codes.. it works !!! It displays out the picture, just that i need to find how to constraint it into a table. >.<
Jan 6 '10 #3

Frinavale
Expert Mod 5K+
P: 9,731
Umm what do you mean "constraint it into a table"?
There can be constraint for a table that restricts the data values that can be added to a table..??

-Frinny
Jan 6 '10 #4

P: 9
Cos now the pictures all are displayed according to the original size....
I want them to have a fixed size for every uploads...
i tried using html method, the width and height thingy but failed..so confusing
I guess i cant fix it till now... lol
Jan 6 '10 #5

Frinavale
Expert Mod 5K+
P: 9,731
I think I know what you're looking for.
Right now your images are different sizes. Some of them are large and some are small.

You could either use the HTML img tag to resize the image to the desired size like this:
Expand|Select|Wrap|Line Numbers
  1. $imgHeight = '150px';
  2. $imgWidth = '150px';
  3. echo "<img src='".$row['picture']."' style='height:".$imgHeight."; width:".$imgWidth." />" ;
Or you could resize (scale) the actual image that exists on the server using PhP. You could do this resizing when the image is uploaded, or you could do this resizing in a PhP page dedicated to sending images to the browser. If you resize the images on the server then you may be saving time and resources for when the image is downloaded and displayed in the browser.

-Frinny
Jan 6 '10 #6

P: 9
Hmmm,the code doesnt work >.<

the picture now has become this :

<img src='uploads/images.jpg' style='height:150px; width:150px />
uploads/images.jpg

<img src='uploads/images.jpg' style='height:150px; width:150px />
uploads/images.jpg
Jan 6 '10 #7

Frinavale
Expert Mod 5K+
P: 9,731
That would probably be because I forgot to close the string I supplied as the style attribute...I should have posted:
Expand|Select|Wrap|Line Numbers
  1. $imgHeight = '150px';
  2. $imgWidth = '150px';
  3. echo "<img src='".$row['picture']."' style='height:".$imgHeight."; width:".$imgWidth."' />" 
......

You should always double check to make sure that your HTML is valid.

-Frinny
Jan 6 '10 #8

P: 9
ic... i really need to buck up in learning all this.. tks a million Frinny :)
Jan 6 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.