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

msg:4228208 | 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"> <tr> <td>Obituary ID Number: </td> <td><input type="text" name="obit_id" /><br/></td> </tr> <tr> <td>First Name: </td> <td><input type="text" name="first_name" /><br/></td> </tr> <tr> <td>Last Name: </td> <td><input type="text" name="last_name" /><br/></td> </tr> <tr> <td>Age: </td> <td><input type="text" name="age" /><br/></td> </tr> <tr> <td>Date of birth: </td> <td><input type="text" value="yyyy-mm-dd" name="dob" /><br/></td> </tr> <tr> <td>Date of decease: </td> <td><input type="text" value="yyyy-mm-dd" name="dod" /><br/></td> </tr> <tr> <td>Obituary Text: </td> <td><textarea rows="20" cols="40" name="obit_text" /></textarea><br/></td> </tr> <tr> <td>Picture: </td> <td><input type="file" name="pic" /></td> </table> <input type="submit" /> <input type="reset" /> </form> >>>>>>>>>>>>>>>>>>>>>> the file that does the stuff.... <?php //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) VALUES ('$_POST[obit_id]','$_POST[first_name]','$_POST[last_name]','$_POST[age]','$_POST[dob]','$_POST[dod]','$_POST[obit_text]','$_POST[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"; mysql_close($con) ?> >>>>>>>>>>>>>>>>>>>>>> this file lists the names... <?php //make a MySQL connection include('config.php'); // echo " <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'> //<tr> //<th>obit_id</th> //<th>lastname</th> //<th>firstname</th> //<th>dod</th> //<th>obit</th> //</tr>"; 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>"; //while($obit_data=mysql_fetch_array($result)){ //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'] . " " . $obit_data['last_name'] . " " . 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'] . " " . $row['last_name'] . "<br/>"; //<a href=\"EDIT.php?id=" . $id . "\"> //print "pagename.php?hackid=".$result["hackid"]; //mysql_close($con); //while($link=mysql_fetch_array($result)){ //echo (display) a link using $link[linkid] //echo "<p>" . $link['lastname'] . "</p>"; //echo " <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.... <?php //make a MySQL connection include('config.php'); //$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()); //while($obit_data=mysql_fetch_array($result)){ while($obit_data=mysql_fetch_array($result)){ echo "<img src='http://www.foxfuneralhomes.com/admin/images/" . $obit_data['pic'] . "' />" . "<br/><br/>"; echo "<h4>" . $obit_data['first_name'] . " "; echo $obit_data['last_name'] . " " . $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()); //while($obit_data=mysql_fetch_array($result)){ //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...
|
Anyango

msg:4228332 | 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?
|
highseas

msg:4228465 | 2:42 pm on Nov 9, 2010 (gmt 0) | Anyango: 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.
|
highseas

msg:4228469 | 2:50 pm on Nov 9, 2010 (gmt 0) | it looks like i have full rights to the folder rwxr-xr-x i was test sending some images to another folder and they are resident in that folder
|
highseas

msg:4228578 | 7:58 pm on Nov 9, 2010 (gmt 0) | SOLVED! I have solved my problem, it was a combination of syntax and pointing to folders and such, the usual suspects. Thanks everyone (especially Anyango)!
|
|
|