<script type="text/javascript">
<!--
$(document).ready(function() {
$('#markItUp').markItUp(mySettings);
});
-->
</script>
<?php
require('../connect.php');
$request_id = $_REQUEST['id'];
if($_POST['cmd'] == "save") {
$title = $_POST['title'];
$date = $_POST['date'];
$price = $_POST['price'];
$summary = $_POST['summary'];
$description = $_POST['description'];
$default_str = $_POST['default'];
$id_str = $_POST['id'];
for ($i = 0; $i < count($default_str); $i++) {
$default = $_POST['default'][$i];
$id = $_POST['id'][$i];
$query = "UPDATE uploads SET `default`='$default' WHERE id='$id'";
mysql_query($query) or die(mysql_error());
}
mysql_query("UPDATE listings SET title='$title' WHERE id='$request_id'") or die(mysql_error());
mysql_query("UPDATE listings SET date='$date' WHERE id='$request_id'") or die(mysql_error());
mysql_query("UPDATE listings SET price='$price' WHERE id='$request_id'") or die(mysql_error());
mysql_query("UPDATE listings SET summary='$summary' WHERE id='$request_id'") or die(mysql_error());
mysql_query("UPDATE listings SET description='$description' WHERE id='$request_id'") or die(mysql_error());
echo '
<script type="text/javascript" language="javascript">
$(function() {
feedBackMessage("formMessage", "positive", "Listing has been updated");
});
</script>';
}
$result = mysql_query("SELECT * FROM listings WHERE id='$request_id'");
while($listing = mysql_fetch_array($result)) {
?>
<div id="form" class="component red">
<h2>Edit a Listing</h2>
<div class="component lightBorder">
<p id="formMessage"></p>
<form id="editListing" name="editListing" action="<?=$_SERVER['php_self']?>" onsubmit="return validateForm(this);" method="post">
<input type="hidden" name="cmd" value="save" style="border: 0px; background: transparent;"/>
<p style="float: right;"><span style="color: red;">*</span> Indicates required fields</p>
<p style="clear: right;">
<label><span style="color: red;">*</span> Title:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="title" value="<?=$listing['title']?>" maxlength="250" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label><span style="color: red;">*</span> Date:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="date" value="<?=$listing['date']?>" maxlength="10" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label><span style="color: red;">*</span> Price:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="price" value="<?=$listing['price']?>" maxlength="250" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label>Summary:</label>
<span style="display: block; margin-left: 110px;">
<textarea name="summary" id="summary" rows="5" cols="40" style="width: 97%;"><?=$listing['summary']?></textarea>
</span>
</p>
<p>
<label>Description:</label>
<textarea id="markItUp" class="markItUpEditor" name="description" rows="5" cols="40"><?=$listing['description']?></textarea>
</p>
<p>
<label>Images:</label>
<span class="listingImages" style="display: block; margin-left: 110px;">
<?
$request_lid = $listing['lid'];
$result1 = mysql_query("SELECT * FROM uploads WHERE listing='$request_lid'") or die (mysql_error());
$i=0;
while ($images = mysql_fetch_array($result1)) {
$i++;
echo "<span class='item'>";
echo "<a href='{$images['upload_dir']}{$images['filename']}' title='{$images['filename']}' class='thickbox' rel='listingImages' style='text-decoration: none;'><img src='{$images['upload_dir']}{$images['filename']}' width='100' border='0' alt='{$images['filename']}' style='margin-bottom: 5px;' /></a><br />";
echo "<input type='hidden' name='id[]' value='".$images['id']."'/><br />";
echo "<input type='text' size='1' id='default' name='default[]' value='{$images['default']}'/>";
echo "</span>";
}
?>
<br style="clear: left;" />
</span>
</p>
<input class="submit" type="submit" name="submit" value="Submit" />
</form>
</div>
</div>
<? } mysql_close($connection); ?>
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
<script type="text/javascript">
<!--
$(document).ready(function() {
$('#markItUp').markItUp(mySettings);
});
-->
</script>
<?php
require('../connect.php');
$request_id = $_REQUEST['id'];
$result = mysql_query("SELECT * FROM listings WHERE id='$request_id'");
while($listing = mysql_fetch_array($result)) {
?>
<div id="form" class="component red">
<h2>Edit a Listing</h2>
<div class="component lightBorder">
<p id="formMessage"></p>
<form id="editListing" name="editListing" action="<?=$_SERVER['php_self']?>" onsubmit="return validateForm(this);" method="post">
<input type="hidden" name="cmd" value="save" style="border: 0px; background: transparent;"/>
<p style="float: right;"><span style="color: red;">*</span> Indicates required fields</p>
<p style="clear: right;">
<label><span style="color: red;">*</span> Title:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="title" value="<?=$listing['title']?>" maxlength="250" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label><span style="color: red;">*</span> Date:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="date" value="<?=$listing['date']?>" maxlength="10" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label><span style="color: red;">*</span> Price:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="price" value="<?=$listing['price']?>" maxlength="250" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label>Summary:</label>
<span style="display: block; margin-left: 110px;">
<textarea name="summary" id="summary" rows="5" cols="40" style="width: 97%;"><?=$listing['summary']?></textarea>
</span>
</p>
<p>
<label>Description:</label>
<textarea id="markItUp" class="markItUpEditor" name="description" rows="5" cols="40"><?=$listing['description']?></textarea>
</p>
<p>
<label>Images:</label>
<span class="listingImages" style="display: block; margin-left: 110px;">
<?
$request_lid = $listing['lid'];
$result1 = mysql_query("SELECT * FROM uploads WHERE listing='$request_lid'") or die (mysql_error());
$count = mysql_num_rows($result1);
while ($images = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$mainImage = $images['main'];
$upload_dir = $images['upload_dir'];
$filename = $images['filename'];
$id[] = $images['id'];
echo "<span class='item'>";
echo "<a href=\"".$upload_dir."".$filename."\" title=\"".$filename."\" class='thickbox' rel='listingImages' style='text-decoration: none;'>";
echo "<img src=\"".$upload_dir."".$filename."\" width='100' border='0' alt=\"".$filename."\" style='margin-bottom: 5px;' />";
echo "</a><br />";
if( $mainImage == '1' ) {
echo "<input type='radio' name='main[]' value=\"1\" checked='checked'/>";
} else {
echo "<input type='radio' name='main[]' value=\"1\"/>";
}
echo "</span>";
}
?>
<br style="clear: left;" />
</span>
</p>
<input class="submit" type="submit" name="submit" value="Submit" />
</form>
</div>
</div>
<?
}
if($_POST['cmd'] == "save") {
$title = $_POST['title'];
$date = $_POST['date'];
$price = $_POST['price'];
$summary = $_POST['summary'];
$description = $_POST['description'];
for($i=0;$i<$count;$i++){
$main = $_POST['main'];
$sql1="UPDATE uploads SET main='$main[$i]' WHERE id='$id[$i]'";
mysql_query($sql1) or die(mysql_error());
//echo $sql1."<br />";
}
mysql_query("UPDATE listings SET title='$title', date='$date', price='$price', summary='$summary', description='$description' WHERE id='$request_id'") or die(mysql_error());
echo '
<script type="text/javascript" language="javascript">
$(function() {
feedBackMessage("formMessage", "positive", "Listing has been updated");
});
</script>';
}
mysql_close($connection);
?>
ASKER
<script type="text/javascript">
<!--
$(document).ready(function() {
$('#markItUp').markItUp(mySettings);
});
-->
</script>
<?php
require('../connect.php');
$request_id = $_REQUEST['id'];
$result = mysql_query("SELECT * FROM listings WHERE id='$request_id'");
while($listing = mysql_fetch_array($result)) {
$request_lid = $listing['lid'];
?>
<div id="form" class="component red">
<h2>Edit a Listing</h2>
<div class="component lightBorder">
<p id="formMessage"></p>
<form id="editListing" name="editListing" action="<?=$_SERVER['php_self']?>" onsubmit="return validateForm(this);" method="post" enctype="multipart/form-data">
<input type="hidden" name="cmd" value="save" style="border: 0px; background: transparent;"/>
<p style="float: right;"><span style="color: red;">*</span> Indicates required fields</p>
<p style="clear: right;">
<label><span style="color: red;">*</span> Title:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="title" value="<?=$listing['title']?>" maxlength="250" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label><span style="color: red;">*</span> Date:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="date" value="<?=$listing['date']?>" maxlength="10" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label><span style="color: red;">*</span> Price:</label>
<span style="display: block; margin-left: 110px;">
<input type="text" name="price" value="<?=$listing['price']?>" maxlength="250" class="required" style="width: 97%;" />
</span>
</p>
<p>
<label>Summary:</label>
<span style="display: block; margin-left: 110px;">
<textarea name="summary" id="summary" rows="5" cols="40" style="width: 97%;"><?=$listing['summary']?></textarea>
</span>
</p>
<p>
<label>Description:</label>
<textarea id="markItUp" class="markItUpEditor" name="description" rows="10" cols="40"><?=$listing['description']?></textarea>
</p>
<p>
<label>Images:</label>
<span class="listingImages" style="display: block; margin-left: 110px;">
<?
$result1 = mysql_query("SELECT * FROM uploads WHERE listing='$request_lid'") or die (mysql_error());
//$count = mysql_num_rows($result1);
while ($images = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$mainImage = $images['main'];
$upload_dir = $images['upload_dir'];
$filename = $images['filename'];
//$id[] = $images['id'];
echo "<span class='item'>";
echo "<a href=\"".$upload_dir."".$filename."\" title=\"".$filename."\" class='thickbox' rel='listingImages' style='text-decoration: none;'>";
echo "<img src=\"".$upload_dir."".$filename."\" width='100' border='0' alt=\"".$filename."\" style='margin-bottom: 5px;' />";
echo "</a><br />";
if( $mainImage == '1' ) {
#assign the id of each bitmap to the radio button
echo "<input type='radio' name='main[]' value='$id' checked='checked'/>";
} else {
echo "<input type='radio' name='main[]' value='$id'/>";
}
echo "</span>";
}
$selectedid;
if (isset($_POST('main[]')) {
$selectedid = $_POST('main[]');
}
$result1 = mysql_query("SELECT id FROM uploads WHERE listing='$request_lid'") or die (mysql_error());
while ($images = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$id = $images['id'];
$val = 0;
if ($id == $selectedId) {
$val = 1;
}
$sql1="UPDATE uploads SET main=$val WHERE id='$id'";
mysql_query($sql1) or die(mysql_error());
}
?>
<br style="clear: left;" />
</span>
</p>
<p>
<?
//upload directory.
//change to fit your need eg. files, upload .... etc.
$upload_dir = "../images/listings/";
//number of files to upload.
$num_files = 5;
//the file size in bytes.
$size_bytes =307200; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png");
//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("<span class=\"feedbackNegative\">Error: The directory <b>($upload_dir)</b> doesn't exist</span><br /><br />");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("<span class=\"feedbackNegative\">Error: The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)</span><br /><br />");
}
//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['submit'])){
echo "<h3>Upload results:</h3>";
//do a loop for uploading files based on ($num_files) number of files.
for ($i2 = 1; $i2 <= $num_files; $i2++) {
//define variables to hold the values.
$new_file = $_FILES['file'.$i2];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];
#-----------------------------------------------------------#
# this code will check if the files was selected or not. #
#-----------------------------------------------------------#
if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "<span class=\"feedbackNegative\">File $i2: Not selected.</span><br /><br />";
}else{
#-----------------------------------------------------------#
# this code will check file extension #
#-----------------------------------------------------------#
$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "<span class=\"feedbackNegative\">File $i2: ($file_name) Wrong file extension.</span><br /><br />";
}else{
#-----------------------------------------------------------#
# this code will check file size is correct #
#-----------------------------------------------------------#
if ($file_size > $size_bytes){
echo "<span class=\"feedbackNegative\">File $i2: ($file_name) Faild to upload. File must be <strong>". $size_bytes / 1024 ."</strong> KB.</span><br /><br />";
}else{
#-----------------------------------------------------------#
# this code check if file is Already EXISTS. #
#-----------------------------------------------------------#
if(file_exists($upload_dir.$file_name)){
echo "<span class=\"feedbackNegative\">File $i2: ($file_name) already exists.</span><br /><br />";
}else{
#-----------------------------------------------------------#
# this function will upload the files. :) ;) cool #
#-----------------------------------------------------------#
if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "<span class=\"feedbackPositive\">File $i2: ($file_name) Uploaded.</span><br /><br />";
//The MySQL query which will insert content into the table.
$query = "INSERT INTO uploads (id, listing, upload_dir, filename) VALUES ('', '$request_lid', '$upload_dir', '$file_name')";
//Executing the query with mysql_query().
mysql_query($query) or die(mysql_error());
}else{
echo "<span class=\"feedbackNegative\">File $i2: Faild to upload.</span><br /><br />";
}#end of (move_uploaded_file).
}#end of (file_exists).
}#end of (file_size).
}#end of (limitedext).
}#end of (!is_uploaded_file).
}#end of (for loop).
# print back button.
//echo "»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
echo "<label>Additional Images:</label>
<span style=\"margin-left: 110px; display: block;\">";
// show the file input field based on($num_files).
for ($i2 = 1; $i2 <= $num_files; $i2++) {
echo "File $i: <input type=\"file\" name=\"file". $i2 ."\"/><br />";
}
echo "<span style=\"display: block; font-size: 0.86em; margin-top: 5px;\">Max file size = ". $size_bytes / 1024 ." KB</span>
</span>
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\"/>";
}
?>
</p>
<input class="submit" type="submit" name="submit" value="Submit" />
</form>
</div>
</div>
<?
}
if($_POST['cmd'] == "save") {
$title = $_POST['title'];
$date = $_POST['date'];
$price = $_POST['price'];
$summary = $_POST['summary'];
$description = $_POST['description'];
//for($i=0;$i<$count;$i++){
//$main = $_POST['main'];
//$sql1="UPDATE uploads SET main='$main[$i]' WHERE id='$id[$i]'";
//mysql_query($sql1) or die(mysql_error());
//echo $sql1."<br />";
}
mysql_query("UPDATE listings SET title='$title', date='$date', price='$price', summary='$summary', description='$description' WHERE id='$request_id'") or die(mysql_error());
echo '
<script type="text/javascript" language="javascript">
$(function() {
feedBackMessage("formMessage", "positive", "Listing has been updated");
});
</script>';
}
mysql_close($connection);
?>
ASKER
Web development includes all aspects of presenting content on intranets and the Internet, including delivery development, protocols, languages and standards, server software, browser clients, databases and multimedia generation.
TRUSTED BY
Can you just loop on...
for ($i = 0; $i < count($_POST['default']);$
...
}