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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.