Hello guys,
I have been trying to submit data that contains both photos and text to a phpmyadmin database using php
The photos work actually, as they are being stored in a folder but the text do not get to the database. i would also like to save a path for the photos at the database as well. here are my codes. any help would be appreciated. thanks
The database is called upgrade
the table is called testimonials
i have columns in the table called: id, name, email client type, comments and image
The image column is meant to store the path of the folder where the photos are being saved
The folder where the photos are being stored is called upload
I have two files. One php and the other html
The php file is called file_upload.php while the html file is called start.html
Below are the codes:
for file_upload.php page:
<?php
if(isset($_POST['add']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db_name = 'upgrade';
$tbl_name = 'testimonials';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db_name")or die("cannot select DB");
$Fname = $_POST['fname'];
$Email = $_POST['email'];
$Content = $_POST['content'];
$Type = $_POST['type'];
$uploadDir = 'upload/';
$fileName = $_FILES['image']['name'];
$filePath = $uploadDir . $fileName;
if(move_uploaded_file($_FILES["image"]["tmp_name"],"upload/".$_FILES["image"]["name"]))
{
// If file has uploaded successfully, store its name in data base
$query_image = "INSERT INTO $tbl_name(fname,email,content,image,type) VALUES ('$Fname','$Email','$Content','$filePath','$Type',";
if(mysql_query($query_image))
{
echo "Stored in: " . "upload/" . $_FILES["image"]["name"];
}
else
{
echo 'Record not stored in database';
}
}
else{echo 'File not uploaded';}
}
For start.html page:
<html>
<head>
</head>
<body>
<br><br><br>
<form method="post" enctype="multipart/form-data" action="/testimonials/file_upload.php">
<table>
<tr>
<td width="250">Name</td>
<td>
<input name="fname" type="text" id="fname" /><br />
</td>
</tr>
<tr>
<td width="250">Email: (will not be publicized)</td>
<td>
<input name="email" type="text" id="email" /><br />
</td>
</tr>
<tr>
<td width="250">Client Type</td>
<td id="mainselection">
<select name="type" id="type">
<option></option>
<option value="Residential">Residential</option>
<option value="Business">Business</option>
</select>
</td>
</tr>
<tr>
<td width="250">Comments</td>
<td>
<textarea id="content" name="content" rows="10" cols="50" style="border-style:groove;box-shadow: 4px 4px 4px 4px #888888;"placeholder="Please describe your experience"></textarea>
</td>
</tr>
<tr>
<td width="250">Image</td>
<td>
<input name="image" type="file" id="file">
</td>
</tr>
<tr>
<td width="250"> </td>
<td>
<input name="add" type="submit" id="add" value="Add Testimonial">
</td>
</tr>
</table>
</form>
thanks all