I have been searching before asking a question to solve my problem. But couldn't quite find anything that solves my problem. What I'm trying to do is upload pictures and some text to a database. The uploading works and the image gets stored as its binary data in a blob variable. The problem is that I want to display the text and images in a table as part of a dynamic html page.
I get all of the text to load to the page correctly, but the images only show up as blank squares (for lack of a better description). If you have any ideas, I'm all for it. Here is the code for everything.
<form action="http://notactualsite/upload.php" method="post" enctype="multipart/form-data">
<table border="0">
<tr>
<td>Select image to upload: </td>
<td><input type="file" name="image" id="image"></td>
</tr>
<tr>
<td>Where is this place?: </td>
<td><input type="text" name="destination" id="destination"></td>
</tr>
<tr>
<td>Why this place?: </td>
<td><input type="textbox" name="reason" id="reason"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Upload" name="submit"></td>
</tr>
</table>
</form>
Now for the uploading php script/program
$servername = "";
$username = "";
$password = "";
$database = "";
$port = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database, $port);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$file = $_FILES['image']['tmp_name'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_size = getimagesize($_FILES['image']['tmp_name']);
$image_name = addslashes($_FILES['image']['name']);
$reason = $_POST['reason'];
$destination = $_POST['destination'];
if($image_size == true)
{
$sqlStr = "INSERT INTO place2go VALUES ('$image_name','$image','$destination','$reason')";
$insert = mysqli_query($conn, $sqlStr);
}
mysqli_close($conn);
header('Location: http://www.is1500finproj-000564723.squarespace.com/place-to-go/');
exit();
?>
now the problem code
$servername = "";
$username = "";
$password = "";
$database = "";
$port = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database, $port);
if ($conn) {
//echo "<h1>TESTING</h1>";
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM place2go";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// create table structure
// output data of each row: a single player with picture and name
while($row = $result->fetch_assoc()) {
echo "<h3>";
echo $row["placeName"]. "</h3>";
echo "<table border=0>";
echo "<tr>";
echo "<td><img src='" . $image . " ' width='50%' /></td>";
echo "<td valign=top style='font-size:10pt'>";
echo $row["placeWhy"]. "</td>";
echo "</tr>";
echo "</table>";
}
}
mysqli_close($conn);
}
?>