Hi,
Still trying to add a portion to my edit_subject.php form for users to upload images to the database; this in turn creates a hyperlink on the form which they can then click on, which in turn will place the image in the correct place on the appropriate web page. :rolleyes:
Below I show the coding for my edit page. How can i add a portion to it to allow users to do the appropriate actions. Do I add to the sql query thats already there or create another one? The text and the images are in two different tables which have no relation to each other. Can I nest an upload and download form within the form itself?
To explain what I mean you can see the form as it is at the following address. Because it has a log in system you will need to use "testtest1" and "testtest1", as username and password: http://www.books3333.com/edit_subject.php
The way the form works is: click on the menu page; this brings up the page to be edited in the relevant boxes. It has an update query for all the individual text boxes on the page.
The coding for the page and form is below:
<?php include("includes/session.php");
include("includes/connect.php");
include("includes/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('menu_name','position', 'visible','head1', 'content1', 'head2', 'content2', 'head3', 'content3','sp_head1', 'sp_cont1', 'sp_head2', 'sp_cont2', 'sp_head3', 'sp_cont3' );
foreach($required_fields as $fieldname){
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))){
$errors[] = $fieldname; //the errors will be $fieldname.
}
}
$fields_with_lengths = array('menu_name' =>30);
foreach($fields_with_lengths as $fieldname => $maxlength){
if(strlen(trim($_POST[$fieldname])) > $maxlength){
$errors[] = $fieldname;}
}
if (empty($errors)){
// catch form data-------------------------------------------------------------------------------
$id = ($_GET['entry']);
$menu_name = mysqli_prep($_POST["menu_name"]);
$position = mysqli_prep($_POST["position"]);
$visible = mysqli_prep($_POST["visible"]);
$head1 = mysqli_prep($_POST["head1"]);
$content1 = mysqli_prep($_POST["content1"]);
$head2 = mysqli_prep($_POST["head2"]);
$content2 = mysqli_prep($_POST["content2"]);
$head3 = mysqli_prep($_POST["head3"]);
$content3 = mysqli_prep($_POST["content3"]);
$sp_head1 = mysqli_prep($_POST["sp_head1"]);
$sp_cont1 = mysqli_prep($_POST["sp_cont1"]);
$sp_head2 = mysqli_prep($_POST["sp_head2"]);
$sp_cont2 = mysqli_prep($_POST["sp_cont2"]);
$sp_head3 = mysqli_prep($_POST["sp_head3"]);
$sp_cont3 = mysqli_prep($_POST["sp_cont3"]);
//query
$query = "UPDATE pages SET
menu_name='{$menu_name}',
position={$position},
visible={$visible},
head1='{$head1}',
content1 = '{$content1}',
head2='{$head2}',
content2 = '{$content2}',
head3='{$head3}',
content3 = '{$content3}',
sp_head1='{$sp_head1}',
sp_cont1 = '{$sp_cont1}',
sp_head2='{$sp_head2}',
sp_cont2 = '{$sp_cont2}',
sp_head3='{$sp_head3}',
sp_cont3 = '{$sp_cont3}'
WHERE id = {$id}";
// 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";
//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="temps1.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['menu_name'];?></h2><br/>
<?php if(!empty($message)){
echo "<p>".$message."</p>";
}
?><form style="background:#FFFFFF; padding:15px; border:thin ridge #666666" action="edit_subject.php?entry=<?php echo urlencode($allpages['id']);?>" method="post">
<p>Subject Name:<input type="text" name="menu_name" id="menu_name" value="<?php echo $allpages['menu_name'];?>"></p>
<p>Position:
<select name="position">
<?php $subject_set = get_menu_names(); /*this calls the function that gets the menu_names and uses that in a for loop to count how many names there are as we may need to jostle around thier positions and so give them different numbers see below:*/
$subject_count = mysqli_num_rows($subject_set);
for($count=1; $count <= $subject_count; $count++){
echo "<option value=\"{$count}\"";
if($allpages['position'] == $count) {
echo " selected";
}
echo ">{$count}</option>";
}
?>
<option value="1"></option>
</select>
</p>
<p>
Visible:
<input type="radio" name="visible" value="0" <?php if($allpages['visible'] == 0){echo " checked";}?> />NO</p>
<input type="radio" name="visible" value="1" <?php if($allpages['visible'] == 1){echo " checked";}?>/>Yes
</p>
<p>Headline 1:<input type="text" name="head1" id="head1" value="<?php echo $allpages['head1'];?>"></p><br/>
<p>Content1:<br/><textarea name="content1" cols="50" rows="10"><?php echo $allpages['content1'];?></textarea></p><br/>
<p>Headline 2:<input type="text" name="head2" id="head2" value="<?php echo $allpages['head2'];?>"></p><br/>
<p>Content2:<br/><textarea name="content2" cols="50" rows="10"><?php echo $allpages['content2'];?></textarea></p><br/>
<p>Headline 3:<input type="text" name="head3" id="head3" value="<?php echo $allpages['head3'];?>"></p><br/>
<p>Content3:<br/><textarea name="content3" cols="50" rows="10"><?php echo $allpages['content3'];?></textarea></p><br/>
<p>Side Panel Headline 1:<input type="text" name="sp_head1" id="sp_head1" value="<?php echo $allpages['sp_head1'];?>"></p><br/>
<p>Side Panel Content1:<br/><textarea name="sp_cont1" cols="50" rows="10"><?php echo $allpages['sp_cont1'];?></textarea></p><br/>
<p>Side Panel Headline 2:<input type="text" name="sp_head2" id="sp_head2" value="<?php echo $allpages['sp_head2'];?>"></p><br/>
<p>Side Panel Content2:<br/><textarea name="sp_cont2" cols="50" rows="10"><?php echo $allpages['sp_cont2'];?></textarea></p><br/>
<p>Side Panel Headline 3:<input type="text" name="sp_head3" id="sp_head3" value="<?php echo $allpages['sp_head3'];?>"></p><br/>
<p>Side Panel Content3:<br/><textarea name="sp_cont3" cols="50" rows="10"><?php echo $allpages['sp_cont3'];?></textarea></p><br/>
<input type="submit" name="submit" value="Edit" />
</form>
the get_subject_by_id function is as follows:
function get_subjects_by_id($subject_id){
global $connection;
$query = "SELECT * FROM pages WHERE id = '$subject_id' ";
$result=mysqli_query($connection,$query);
confirm_query($result);
if($subject = mysqli_fetch_array($result)){
return $subject;
}else{
return NULL;
}
}
When answering bear in mind Im a complete novice with forms and images so please S-p-e-l-l it out๐
Thank you for helping with this. I know its a long question and Ive probably made it mpore complex than it needs to be. but I hope it makes it clear๐
cass27