Avatar of tonybobdesign
tonybobdesignFlag for United States of America

asked on 

PHP - Updating multiple rows and tables in one form. What am I doing wrong?

I am creating a very insecure form at the moment so I will fix my post values and secure them when I have it working..  I have a friend that is a Realtor and needs a cpanel to create and modify and delete her property listings.  Well besides the typical record information such as title, summary, and description...  the administrator also has the ability to upload multiple images that associate to that specific listing they were creating.  When you grab the id of the record to modify it, I would like to change a single value by the name of `default`to 1 or 0 that is attached to each image associating with the listing that is currently being edited.  This value represents the default image in the gallery.  When viewing the record from the front end, You have a default image on the left and then the rest of the images in another part of the layout.  

My issue is that before I added this functionality to update multiple rows, I was able to click on submit get my success message and then title, date, price, summary, and description were all updated.  Now when I added in the loop and query to update the multiple records, I can't get to the success message and the multiple records update like they should, but then the rest of the fields don't get updated.  Please help and I greatly appreciate it.  
<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); ?>

Open in new window

Web DevelopmentScripting Languages

Avatar of undefined
Last Comment
seippg
Avatar of seippg
seippg
Flag of United States of America image

Your app is probably 'die'ing in the query.

Can you just loop on...


for ($i = 0; $i < count($_POST['default']);$i++) {
...
}
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

Do I just replace your loop with the one i have?  Example:

from:
for ($i = 0; $i < count($default_str); $i++) {

to:
for ($i = 0; $i < count($_POST['default']);$i++) {

Do you have an idea of how to debug?  The weird thing is without the loop all together I get the rest of the fields to update, but when the loop is executed it seems to only update results relevant to that loop.  

Should I execute the query outside of the loop so it does not die?  But if i do that then I only get one query submitted...
Avatar of seippg
seippg
Flag of United States of America image

Do I just replace your loop with the one i have?  Example:
>>yes

from:
for ($i = 0; $i < count($default_str); $i++) {

to:
for ($i = 0; $i < count($_POST['default']);$i++) {

Do you have an idea of how to debug?  

<<I use a PHP debugger from time to time though typically I just insert HTML statements or
<< log entries.  I have a cheap & easy log module I created that I can put values in (see below) though
there are existing logging mechanisms that I use for larger apps.


The weird thing is without the loop all together I get the rest of the fields to update, but when the loop is executed it seems to only update results relevant to that loop.  

<<That's probably because it's looping beyond the end of the array...the last entry probably doesn't
<<have valid values and it's dieing.  The code I gave should stop that.  You could confirm by looking in
<< the error log for the web server.

Should I execute the query outside of the loop so it does not die?

<<Inside

  But if i do that then I only get one query submitted...

<<By the way....you could combine up those Updates after the loop into one statement...more efficient.

<<here's my cheap and easy log...

<?php

define("CRITICAL", "4");
define("ERROR", "3");
define("WARNING", "2");
define("INFO", "1");

$configlevel = INFO;

function ptlog($level, $msg)
{
// open file
if ($level > $configlevel) {

      switch ($level) {
            case CRITICAL:
                  $prefix = "Critical Error";
                  break;
            case ERROR:
                  $prefix = "Error";
                  break;
            case WARNING:
                  $prefix = "Warning";
                  break;
            case INFO:
                  $prefix = "Info";
                  break;            
      }      
}

$fd = fopen("../logs/app.log", "a");
// append date/time to message
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] $prefix: $msg";
// write string
fwrite($fd, $str . "\n");
// close file
fclose($fd);
}
?>
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

Alright I combined the queries into what i have now,

mysql_query("UPDATE listings SET title='$title', date='$date', price='$price', summary='$summary', description='$description' WHERE id='$request_id'") or die(mysql_error());

optimizing rather then fixing, but thats a start?  

I don't mean to be naive but how do i implement that log?  I will take your advice though and look at the error log real quick.  

It's still dying by the way..
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

I have unsecured variables and would like to keep my server intact but here is my hosted link to what I have for now.  I will take it down if I get issues...

http://tonybobdesign.com/alco/admin/index.php?admin=editListing&id=2
Avatar of seippg
seippg
Flag of United States of America image

You can put the log snippet in a mylog.pm and include it at the top of your code.  Let me know what your log says.  Also, why don't you try hardcoding the loop for a test...

or ($i = 0; $i < 1;$i++) {

That may tell you something.
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

And sad but I cant even find how to look at the log.  I access a cpanel to modify settings on my server and ftp for everything else.  Any ideas?
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

I get an error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/tonybobd/public_html/alco/admin/editListing.php on line 1

I need to replace variables right?  If so, which ones..

And when hard coding the loop still dies..
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

I also noticed that when i take out the loop all together it dies, but when i take out the query that grabs the data from uploads to display the rows of images, it executes just fine, in a way... it skips the multiple update all together ofcourse.  I'm not sure if I am being specific enough but yeah when i take the while statment it works as in the rest of the fields update.  
Avatar of seippg
seippg
Flag of United States of America image

well, then it's the while loop that's the problem. Looking at that one thing that stands out is
while ($images = mysql_fetch_array($result1)) {
but the way you're accessing the data is by name...that requires a second parm...
while ($images = mysql_fetch_array($result1,  MYSQL_ASSOC)) {

I would echo one of those variables out to the html page to confirm the problem and that the fix works.
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

When I echo $result1 I get:

result1 = Resource id #10

and it still dies with MYSQL_ASSOC.  I take out the entire while loop and its fine, i just dont get it....
Avatar of seippg
seippg
Flag of United States of America image

well...I'll tell you this...only from experience.  I always extract variables from arrays and associative arrays *before* I echo them...saves me tons of times messing around with complex strings.

E.g.
$imagename = $images['name'];

echo "Image Name $imagename";

Problems like one I just found in one of your lines...

src='{$images['upload_dir']}{$images['filename']}'

That won't work...you have single quotes embedded inside of single quotes.  You'd have to use a combination of single and double quotes to fix that.  Reduce your variables first then echo the simplified variables in your output.  Save yourself trouble.
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

Ok I will give that a shot, I'm about to get off of work so I'm gonna have to wrap this up, I would like to get into this again tomorrow if you get the time to...  ill be in touch.  Thank you so much for your help thus far!
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

Still not work for me with everything that you said to do, I can't figure out that log though cuz of the error i get.  Any other ideas?  Would posting my sql from my database help?
Avatar of seippg
seippg
Flag of United States of America image

post your latest php.  I'll see if anything jumps out at me.
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

I actually got it to work but now im working on getting the original input text fields to work as radio buttons for a value of either 1 or 0:

if 1 then checked
if 0 then not checked

How would I go about submitting the checked radio input as a 1 and the rest as a 0?  Code attached.
<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);
?>

Open in new window

Avatar of seippg
seippg
Flag of United States of America image

If I understand the question, it looks as though you are mixing up the bitmap statuses with their IDs...though I can see that you are getting on the right path by extracting the ID from the table.  Here's your while loop modified just a bit.  I added comments.  

#using * in a sql statement is a bad idea...enumerate the columns you need so that if the table is modified you don't get burned.
$result1 = mysql_query("SELECT main, upload_dir, filename, id FROM uploads WHERE listing='$request_lid'") or die (mysql_error());
                                       
                                   
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>";

}

Notice that the value of each radio button now corresponds to the $id of the bitmap.  Now, if we modify your save loop with the understanding that you want to assign 1 to the selected bitmap and 0 to the ones that are not selected....

$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());
}
 
Does this make sense?  I didn't run the code so there may  be a tweak needed but the paradigm should be sufficient to get you going.
Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

I got:

Parse error: syntax error, unexpected '(', expecting ',' or ')' in /home/tonybobd/public_html/alco/admin/editListing.php on line 86

Anyway I can do that update query on the on submit like I have everything else?


<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);
?>

Open in new window

Avatar of tonybobdesign
tonybobdesign
Flag of United States of America image

ASKER

I also I forgot to add to add:

$id = $images['id'];

in the first while loop so I added that back in and still that parse error..
ASKER CERTIFIED SOLUTION
Avatar of seippg
seippg
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Web Development
Web Development

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.

78K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo