473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

help for broken link

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
8 2272
Frinavale
9,735 Expert Mod 8TB
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
punk86
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
9,735 Expert Mod 8TB
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
punk86
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
9,735 Expert Mod 8TB
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
punk86
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
9,735 Expert Mod 8TB
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
punk86
9
ic... i really need to buck up in learning all this.. tks a million Frinny :)
Jan 6 '10 #9

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

Similar topics

9
by: Steve | last post by:
Hello, I am writing a script that calls a URL and reads the resulting HTML into a function that strips out everthing and returns ONLY the links, this is so that I can build a link index of various...
17
by: Razzel | last post by:
I created this as a test: #include <time.h> main(){ printf(X1: %s\n", putim()); printf(X2: %s\n", putim()); } putim() { time_t t; time(&t); return(ctime(&t));
28
by: Craig Cockburn | last post by:
I have a tool which tells me the number of times that visitors attempt to access a link from my site to an external site and what the response code received was. In the event of the remote site...
2
by: vbgunz | last post by:
Hello! this is the main error: http://img406.imageshack.us/img406/5218/screenshotxchmerror1ae.png navigation link images broken here:...
0
by: Josema | last post by:
Hi, Im making an asyncronous application that will detect broken links inside a web site. the question is that i have a tree view in my windows form application, and when a person enters a...
1
by: atombee | last post by:
Hi- this is the project that will not end! (sure you've all been there). I had originally purchased a php/css nav bar for the client, but it was buggy as hell, so I decided to do in css, in which I...
0
by: preetkanwal0678 | last post by:
Hello all, Am working on PYTHON +BRANWAVE(framework) Actually am Trying 2 make a tree menu using d both. Am not able 2 target the (.tmpl) files and not getting how 2 make frames in...
3
by: Giampaolo Rodola' | last post by:
Hi there, I would like to know if such function would be correct for verifying if a link is broken and/or circular. def isvalidlink(path): assert os.path.islink(path) try: os.stat(path)...
0
by: John Dalberg | last post by:
Every link on the web I tested to download the C# snippets links to page on MS's which is broken. Anyone knows a download link which work? Broken page: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.