Hi
I have created a form that uploads text and an image to a web page. However it is the image download to the web page I am having problems with. I do not know how to use a script to specifically download the image from the database that has just been uploaded. (it will only download using: SELECT 'filename' FROM photographs WHERE id = '5'; for instance.
There are two mysqli tables. One for images (photographs) and one for text (careshowkit). Once the use has chosen an image and put in text for page he is taken to a hyperlink to the relative web page.
the pages can be seen at (for input):http://www.louandelcats.co.uk/testingphp/astafftest/1inputform.php[/URL]
and the page where its going to:http://www.louandelcats.co.uk/testin...formstreet.php
The code for 1inputform is as follows:
The code for formstreet.php is:PHP Code:<?php
// include("session.php");
include("../../connect/connection.php");
include("functions.php");
//confirm_logged_in();
//in the tutorial this is changed to find selected subjects function (below down to header)
/*--------------------------------------------script starts here--------------------------------
validation*/
if (isset($_POST['submit'])) { //if the page has been submitted submit is the submit button
$errors = array(); // the array called errors will hold all the errors.
$required_fields = array('page','title', 'content1','subtitle1', 'content2', 'subtitle2', 'content3', 'subtitle3', 'content4','permission');
foreach($required_fields as $fieldname){
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))){
$errors[] = $fieldname; //the errors will be $fieldname.
}
}
if (empty($errors)){
// catch form data-------------------------------------------------------------------------------
$id = ($_GET['entry']);
$page = mysqli_prep($_POST["page"]);
$title = mysqli_prep($_POST["title"]);
$content1 = mysqli_prep($_POST["content1"]);
$subtitle1 = mysqli_prep($_POST["subtitle1"]);
$content2 = mysqli_prep($_POST["content2"]);
$subtitle2 = mysqli_prep($_POST["subtitle2"]);
$content3 = mysqli_prep($_POST["content3"]);
$subtitle3 = mysqli_prep($_POST["subtitle3"]);
$content4 = mysqli_prep($_POST["content4"]);
$permission = mysqli_prep($_POST["permission"]);
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
$type = $_FILES['file_upload']['type'];
$size = $_FILES['file_upload']['size'];
$caption = $_POST['caption'];
$upload_dir = "uploads";
//query
$query = "INSERT INTO cms_careshowkit (page,title,content1,subtitle1,content2,subtitle2,content3,subtitle3,content4,permission)".
"Values('$page','$title','$content1','$subtitle1','$content2','$subtitle2','$content3','$subtitle3','$content4','$permission')";
// execute query
$result = mysqli_query($connection, $query);
// test to see if the update worked
if (mysqli_affected_rows($connection) == 1){
// success
$message = "The subject was successfully updated";
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)){
$message = "File uploaded successfully!";
$query3 = "INSERT INTO photographs (filename,type,size,caption)".
"Values('$target_file','$type','$size','$caption')";
$message = "File $fileName uploaded";
$result = mysqli_query($connection, $query3);
}else{
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}
$query2 = "SELECT id, title FROM cms_careshowkit";
$result = mysqli_query($connection, $query2) or die('Error, query failed');
if(mysqli_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $title) = mysqli_fetch_array($result))
{
?>
<a href="formStreet.php?id=<?php echo $id ;?>"><?php echo $title;?></a></br>
<?php
}
}
//return $result;
}else{
//update failed
$message = "The subject update failed";
$message .= "".mysqli_error($connection);
}
}else{
// errors occured
$message = "There were " .count($errors). " errors in the form";
}
} // end of issset post
/*----------------------------------------------script ends here-----------------------------------*/
if(isset($_GET['entry'])){
$sel_name = $_GET['entry'];
}else{
$sel_name = "";
}
$allpages = get_subjects_by_id($sel_name);
//include("../includes/header.php");
?>
<link href="../articles/content1.css" rel="stylesheet" type="text/css">
<div class="menu">
<?php //navigation($sel_name); ?>
</div><!--end menu-->
<div class="maincontent1"><h2>Edit Subject: <?php echo $allpages['page'];?></h2><br/>
<?php if(!empty($message)){
echo "<p>".$message."</p>";
}
?>
<?php $all_pics = get_pics_by_id($field1, $field2, $id);?>
<form style="background:#FFFFFF; padding:15px; border:thin ridge #666666" action="1inputform.php?entry=<?php echo urlencode($allpages['id']);?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="file" name="file_upload" /><br/>
<input type="text" name="caption" /><br/>
<p>Page:<input type="text" name="page" id="page" value="<?php echo $allpages['page'];?>"></p><br/>
<p>Title:<input type="text" name="title" id="title" value="<?php echo $allpages['title'];?>"></p><br/>
<p>Content1:<br/><textarea name="content1" cols="50" rows="10"><?php echo $allpages['content1'];?></textarea></p><br/>
<p>subtitle1:<input type="text" name="subtitle1" id="subtitle1" value="<?php echo $allpages['subtitle1'];?>"></p><br/>
<p>Content2:<br/><textarea name="content2" cols="50" rows="10"><?php echo $allpages['content2'];?></textarea></p><br/>
<p>subtitle2:<input type="text" name="subtitle2" id="subtitle2" value="<?php echo $allpages['subtitle2'];?>"></p><br/>
<p>Content3:<br/><textarea name="content3" cols="50" rows="10"><?php echo $allpages['content3'];?></textarea></p><br/>
<p>subtitle3:<input type="text" name="subtitle3" id="subtitle3" value="<?php echo $allpages['subtitle3'];?>"></p><br/>
<p>content4:<br/><textarea name="content4" cols="50" rows="10"><?php echo $allpages['content4'];?></textarea></p><br/>
<p>permission:<input type="text" name="permission" id="permission" value="<?php echo $allpages['permission'];?>"></p><br/>
<input type="submit" name="submit" value="Edit" />
</form>
Inm other words I need it to be embedding the image that has just been uploaded. Can anyone help?PHP Code:<?php require_once('../../connect/connection.php');
include("functions.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Kitten Central</title>
<script type="text/javascript" language="JavaScript1.2" src="../../menu.js"></script>
<style type="text/css">
<!--
.style3 {
font-size: 10px;
color: #000000;
}
.style4 {color: #FF0000}
.style5 {color: #008000}
.style6 {color: #808080}
-->
</style>
<link href="../../articles/content1.css" rel="stylesheet" type="text/css" />
</head>
<body background="../../images/catchatstuff/orangeback.jpg" >
<div id="wrapper">
<div id="banner"><img src="../../images/catchatstuff/newbanner2.gif" align="left" alt="banner index" width="964" height="80" border="2" /></div>
<div id="ccbox"><img src="../../images/catchatstuff/catchatlogo3.gif" width="200" height="100" border="0" usemap="#Map" />
<map name="Map" id="Map"><area shape="rect" coords="12,9,187,93" href="../../phpbb/index.php" />
</map></div>
<div id="menu"><?php require("../../includes/addmenu.js");?>
</div>
<?php
$id = $_POST['id'];
$query = "SELECT filename, caption FROM photographs Where id = '{$id}' ";
$result = mysqli_query($connection, $query) or die ('Error, Query Failed' );
$row = mysqli_fetch_array( $result );
?>
<div id="marklogo"><a href="http://www.markets2000.co.uk"><img src="../../images/catchatstuff/design graphic.gif" alt="web site design by markets2000" width="127" height="60" border="0" usemap="#Map11" /></a>
<map name="Map11" id="Map11"><area shape="rect" coords="13,7,116,54" href="http://www.markets2000.co.uk" />
</map></div>
<div id="mainarea">
<div id="mainbody">
<div class="banner"></div>
<div id="headline3"><h2 align="center"><?php insertshowkit("title", $id );?></h2>
</div>
<div id="headline3"><p style="font-size:14px"><?php insertshowkit("content1", $id);?></p></div>
<div id="headline3"><h3 align="left" style="color:#3399CC"><?php insertshowkit("subtitle1", $id);?></h3></div><br/>
<div id="headline3"><p style="font-size:14px">
<?php insertshowkit("content2", $id);?></p></div>
<div id="headline3"><h3 align="left" style="color:#3399CC"><?php insertshowkit("subtitle2", $id);?></h3></div>
<div id="headline3"><p style="font-size:14px"><?php insertshowkit("content3", $id);?></p></div>
<div id="headline3"><h3 align="left" style="color:#3399CC"><?php insertshowkit("subtitle3", $id);?></h3></div>
<div id="headline3"><p style="font-size:14px"> <?php // This assumes filename is similar to image.jpg
echo "<img src=\"uploads/".$row['filename']."\"/><br>".$row['caption'];?> <?php insertshowkit("content4", $id);?></p></div>
</div>
<?php require("../../includes/footer.php");
?>
cass27![]()





Bookmarks