homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

gathering data from a form, posting to db, and displaying
php mysql for image and text

Msg#: 4228206 posted 9:36 pm on Nov 8, 2010 (gmt 0)

I have created an obituary form to gather text and an image, post the text and the image location to a mysql database, and then listing out the rows where the user can select a name, click on that person and then see the image of that person and the text, all gathered from the form.

I cannot get the image to get onto the server and then get the image to render on the web page after the user clicks on the person's name.

I am so close, with another example that works but is not exactly quite the thing I require.

Here are my files....

input form....

<form enctype="multipart/form-data" action="insert-obits.php" method="post">
<table width="500">
<td>Obituary ID Number: </td>
<td><input type="text" name="obit_id" /><br/></td>
<td>First Name: </td>
<td><input type="text" name="first_name" /><br/></td>
<td>Last Name: </td>
<td><input type="text" name="last_name" /><br/></td>
<td>Age: </td>
<td><input type="text" name="age" /><br/></td>
<td>Date of birth: </td>
<td><input type="text" value="yyyy-mm-dd" name="dob" /><br/></td>
<td>Date of decease: </td>
<td><input type="text" value="yyyy-mm-dd" name="dod" /><br/></td>
<td>Obituary Text: </td>
<td><textarea rows="20" cols="40" name="obit_text" /></textarea><br/></td>
<td>Picture: </td>
<td><input type="file" name="pic" /></td>

<input type="submit" /> <input type="reset" />

the file that does the stuff....


//This is the directory where images will be saved
$target = "images/"; $target = $target . basename( $_FILES['pic']['name']);

$con = mysql_connect("#*$!.xx.#*$!.x","#*$!x","#*$!x");
if (!$con)
die('Could not connect: ' . mysql_error());

mysql_select_db("foxfuneralho", $con);

$sql="INSERT INTO obits (obit_id, first_name, last_name, age, dob, dod, obit_text, pic)

//Writes the photo to the server
if(move_uploaded_file($_FILES['pic']['tmp_name'], $target)) {
//Tells you if its all ok

echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded and your information has been added to the obituary system."; }
else {
//Gives and error if its not
echo "We could not upload this file.";

if (!mysql_query($sql,$con))
die('Error: ' . mysql_error());
echo "1 record added";


this file lists the names...

//make a MySQL connection
// echo "&nbsp;<a href=\"insert.php\">INSERT PHP</a><br>";
//get all the data from the page table
//*=select everything from the table page
$result = mysql_query("SELECT * FROM obits")
or die(mysql_error());

//echo "<table border='2' width= '1000'>

while($obit_data = mysql_fetch_array($result))
// {
// echo "<tr>";
// echo "<td width='4'>" . $row['obit_id'] . "</td>";
// echo "<td width='30'>" . $row['last_name'] . "</td>";
// echo "<td width='30'>" . $row['first_name'] . "</td>";
// echo "<td width='10'>" . $row['dod'] . "</td>";
// echo "<td width='500'>" . $row['obit_text'] . "</td>";
// echo "</tr>";
// }
//echo "</table>";

//echo "<a href=\"show-obituaries.php?id=".$obit_data['obit_id']."#*$! you";
//echo $obit_data['first_name']." ".$obit_data['last_name']." </a>";
//echo "<br><br>";

//date("l, F d, Y",strtotime($myrow['date'])); <<< from erika stokes' cool website [erikaqstokes.com...]

echo "<a href='show-obituaries.php?id=$obit_data[obit_id]'>" . $obit_data['first_name'] . "&nbsp;" . $obit_data['last_name'] . "&nbsp; &nbsp;" . date("l, F d, Y",strtotime($obit_data['dod'])) . "</a>" . "<br/>";

//echo "<a href=\webpage.php?id=$row[obit_id]\>" . "Person Here" . "</a>" . $row['first_name'] . "&nbsp;" . $row['last_name'] . "<br/>";

//<a href=\"EDIT.php?id=" . $id . "\">
//print "pagename.php?hackid=".$result["hackid"];


//echo (display) a link using $link[linkid]
//echo "<p>" . $link['lastname'] . "</p>";
//echo "&nbsp;<a href=\"webpage.php?id=$link[linkid]\">Web Page 1</a><br>";
//echo "<a href=\"webpage.php?id=$row[obit_id]\">obits list</a><br>";


this file will output the stuff for each name on the page list from above....

//make a MySQL connection

//$the_id = $_GET['id'];
//$result = mysql_query("select * from obits where obit_id = '$the_id'")
//or die(mysql_error());

$the_id = (int)$_GET['id'];
$result = mysql_query("SELECT * FROM `obits` WHERE `obit_id` = ".$the_id." ")
or die(mysql_error());

//$result = mysql_query("select * from obits")
//or die(mysql_error());

echo "<img src='http://www.foxfuneralhomes.com/admin/images/" . $obit_data['pic'] . "' />" . "<br/><br/>";
echo "<h4>" . $obit_data['first_name'] . "&nbsp;";
echo $obit_data['last_name'] . "&nbsp;&nbsp;" . $obit_data['age'] . "</h4>";
//echo $obit_data['age'];
//echo $obit_data['dod'];
//echo $obit_data['dob'];
echo $obit_data['obit_text'] . "<br/><br/>";
echo "<br/><br/>";

//the_id = $_GET['id']
//$result = mysql_query("select * from obit where obit_id = " + $the_id)
//or die(mysql_error());

//echo "$obit_data['first_name'] $obit_data['last_name'] <br>";
//echo "$obit_data['dob']

//and so on...

//echo "<br><br>";


If someone could "fix" my code haha, I would "gladly pay you Tuesday..."

Thanks for any help with this nettlesome project...



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4228206 posted 7:32 am on Nov 9, 2010 (gmt 0)

Is the image not even being uploaded ? have you checked for file permissions for that directory ? or is it that the image is not being shown even after the upload?


Msg#: 4228206 posted 2:42 pm on Nov 9, 2010 (gmt 0)


well, it appears neither, but I was able to get something working with different code on my local server, so righ tnow this code does not appear to place the image on the server, there appears to be a blob data placement, and when i try to display the obit with the image, the obit text appears and the image does not, just the icon to show that an image is supposed to be there and the reference is for <img src="www.foxfuneralhomes.com/images/ARRAY" /> or something like that.


Msg#: 4228206 posted 2:50 pm on Nov 9, 2010 (gmt 0)

it looks like i have full rights to the folder


i was test sending some images to another folder and they are resident in that folder


Msg#: 4228206 posted 7:58 pm on Nov 9, 2010 (gmt 0)


I have solved my problem, it was a combination of syntax and pointing to folders and such, the usual suspects.

Thanks everyone (especially Anyango)!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved