Jump to content

A better way than using a cluster of arrays ?


Cenobitez

Recommended Posts

I am adding an image rating, privacy and comments system into my image upload script.

 

Because I can handle a variable amount of file uploads, I pass a hidden variable called 'count' to tell me how many was uploaded.

 

I then use a cluster of arrays to do what I need.

 

The code looks messy, and I expect may turn into a disaster.

 

This isnt for general public use, its more a way for me to upload and add images to my own gallery that just me, and a few friends will use, also not added any security to check the data is what I expect as I want to get it working first :)

 

Currently the script workings when I pass it the info, but wondering if anyone could suggest a better way ?

 

<?php 
if (isset($_POST['subcom'])) { //subcap
$count = $_POST['count'];
include('./includes/mysql_connect.inc.php');
for ($i = 1; $i <= $count; $i++) {
	$caption[$i] = $_POST["caption$i"];
	$rate[$i] = $_POST["rate$i"];
	$visible[$i] = $_POST["visible$i"];
	if($visible[$i] =="" or $visible[$i] == "off") {
	$visible[$i] = 0; 
	}else{
	$visible[$i] = 1;
	}
	$file[$i] = $_POST["file$i"];
	$query[$i] = "UPDATE images SET img_caption = '$caption[$i]', img_rating = '$rate[$i]', img_visible = '$visible[$i]' WHERE img_filename = '$file[$i]'";
  		$result[$i] = mysql_query($query[$i]); 
if($result[$i]) { //result
	if($debug[$i] =="1") { //debug
	echo "Result $i: " . $result[$i] . "<br>\n";
	echo "Query $i: " . $query[$i] . "<br>\n";
	echo "Caption $i: " . $caption[$i] . "<br>\n";
	echo "File $i: " . $file[$i] . "<br>\n";
	echo "Visible $i: " . $visible[$i] . "<br>\n";
	echo "Rate $i: " . $rate[$i] . "<br>\n";
	} //debug
	echo "Comments Sucessfully Added for $file[$i] <br />\n";
} else { //result
		echo "Database Entry Error<br/> \n";
		echo mysql_errno($result[$i]) . ": " . mysql_error($result[$i]) . "<br/> \n";
} //result
} //file
} //end subcap
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.