help for broken link

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • punk86
    New Member
    • Jan 2010
    • 9

    help for broken link

    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
    Code:
    <?php
    $HOST = 'localhost';
    $USERNAME = 'root';
    $PASSWORD = '';
    $DB = 'c203';
    	
    $link = mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB) or die(mysqli_connect_error());
    $sql = "SELECT name,birthday,nationality,age,biography,picture FROM stars";
    $result = mysqli_query($link, $sql) or die(mysqli_error($link));
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    		<title>StarGazer</title>
    	</head>
    	<body>
    		<h1>StarGazer</h1>
    		<hr />
    		<h2>Welcome</h2>
    		<table border='1' cellpadding='0' cellspacing='0'>
    <?php
    	while($row=mysqli_fetch_assoc($result)){
    		echo "<tr>";
    		echo "<td>".$row['picture']."</td>";  
    		echo "<img src='picture/" ;
    		echo "</tr>";	
    		
    		
    		//use $row and IMG SRC
    	}
    
    
    
    ?>		
    		</table>
    	</body>
    </html>
    Codes for my index.php

    Code:
    <?php
    // find the code that only do INSERT
    $name = $_POST['name'];
    $birthday = $_POST['birthday'];
    $nationality = $_POST['nationality'];
    $age = $_POST['age'];
    $biography = $_POST['biography'];
    
    	$target_path = "uploads/";
    	$target_path = $target_path . basename( $_FILES['upfile']['name']); 
    	if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path . basename ( $_FILES['upfile']['name']))) {
    		echo "The file ".  basename( $_FILES['upfile']['name']). " has been uploaded. Please click <a href=index.php>here </a> ";
    	}
    	else{
        echo "There was an error uploading the file, please try again!";
    		}
    		
    		
    	$host = 'localhost';
    	$username = 'root';
    	$password = '';
    	$db = 'c203';
    
    	$link = mysqli_connect($host,$username,$password,$db);{
    	$query = "INSERT INTO stars(name,birthday, nationality,age,biography,picture) 
    	VALUES('$name','$birthday','$nationality','$age','$biography','$target_path')";
    	$result = mysqli_query($link, $query) or die(mysqli_error($link));
    		}	 
    	
    	$message = "Name : " . $name . "<br />";
    	$message1 = "Birthday : " . $birthday . "<br />";
    	$message2 = "Nationality : " . $nationality . "<br />";
    	$message3 = "Age : " . $age. "<br />";
    	$message4 = "Biography : " . $biography . "<br />";
    	
    	
    
    	
    ?>
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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:
    Code:
    echo "<img src='picture' />" ;
    Or if you are retrieving the url to the picture from the database...it should be:
    Code:
    echo "<img src='".$row['picture']."' />" ;
    -Frinny

    Comment

    • punk86
      New Member
      • Jan 2010
      • 9

      #3
      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. >.<

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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

        Comment

        • punk86
          New Member
          • Jan 2010
          • 9

          #5
          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

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            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:
            Code:
            $imgHeight = '150px';
            $imgWidth = '150px';
            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

            Comment

            • punk86
              New Member
              • Jan 2010
              • 9

              #7
              Hmmm,the code doesnt work >.<

              the picture now has become this :

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

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

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                That would probably be because I forgot to close the string I supplied as the style attribute...I should have posted:
                Code:
                $imgHeight = '150px';
                $imgWidth = '150px';
                echo "<img src='".$row['picture']."' style='height:".$imgHeight."; width:".$imgWidth."' />"
                ......

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

                -Frinny

                Comment

                • punk86
                  New Member
                  • Jan 2010
                  • 9

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

                  Comment

                  Working...