I am very new to php and mysql. I have read and re-read many forum posts on this subject, but I just cannot figure this out. I have been at it for almost two weeks now.
This is my hope: Load images and captions from a database into an html form. Captions, if existing, are displayed in a textarea below the picture so that they can be changed/updated/deleted. When user clicks on the Update button, the new/old captions are inserted into the database. All this is so that the images and captions can be displayed on a different website "automatically."
I have used a lot of code from many sources. I got it working on my localhost, but when I went live it no longer worked (live version deleted all the image_filename and description data from the database). I think this is because on the live server register_globals=Off. I need to be able to update just the descriptions (captions) for the images via the database.
Much of this code is sectioned into includes so that I can use it on several webpages/sites.
Please help me. So many of you are such excellent programmers, I am in awe of your abilities.
Here is my code:
<?php ob_start();
require_once('drfinn_sessionStart.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Image Tags</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<?php
// Validate user is logged in and set menu
require_once('imageUpdateLoginValidationCode.php');
// Define database connection constants
define('DB_HOST', 'localhost');
define('DB_USER', 'user');
define('DB_PASSWORD', 'pass');
define('DB_NAME', 'imgdb');
// Define application standards
define('FF_IMAGEPATH', 'images/sculpture/');
$tbl_name = "sculpture";
// Retrieve the image data from MySQL
$query = "SELECT * FROM $tbl_name ORDER BY image_filename ASC";
$result = mysqli_query($dbc, $query);
// Count table rows
$count=mysqli_num_rows($result);
?>
<h3>Update image tags</h3><br />
<form name="form1" method="post" action="">
<table width="600" border="1" cellspacing="1" cellpadding="5">
<?php
// Loop through data to create a table in the form of all images in the table with descriptions
while($row=mysqli_fetch_array($result)){
?>
<tr>
<td align="center"><?php $id[]=$row['id']; ?><input name="image_filename[]" type="hidden" id="image_filename" value="<? echo $row['image_filename']; ?>"><img src="<?php echo FF_IMAGEPATH;?><?php echo $row['image_filename']; ?>" alt="" /></td></tr>
<tr>
<td><strong>Description: </strong><textarea name="description[]" id="description" cols="60" rows="2"><? echo $row['description']; ?></textarea></td>
</tr>
<tr>
<td><a href="#update">Go To Update Button</a></td>
</tr>
<?php
}
?>
<tr>
<td align="center"><a name="update"></a><input type="submit" name="submit" value="Update Image Descriptions"></td>
</tr>
</table>
</form>
<?php
// Check if button name "Submit" is active, do this
if (isset($_POST['submit'])) {
for($i=0;$i<$count;$i++){
$query1="UPDATE $tbl_name SET image_filename='$image_filename[$i]', description='$description[$i]' WHERE id='$id[$i]'";
$result1=mysqli_query($dbc, $query1);
}
}
// Redirect back to form
if($result1){
header('location:imageUpdate-sculpture.php');
}
mysqli_close($dbc);
?>
</body>
</html>
<?php ob_flush(); ?>