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
Codes for my index.php
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>
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 />";
?>
Comment