Hmm...don't seem to be getting anywhere with this. Going around in circles(!)
Anyone else fancy giving this a shot?
<?php # second stage of editing offers
require_once('../dbc/connect.php');
$page_title = "Footer Logos";
include ('../include/aheadit.html');
if (($_SESSION['usercat']!='a')) {
echo 'Sorry, you are not logged in';
exit;
}
// change what logos are displayed on site
if (isset($_POST['submitted'])) {
if (($_SESSION['user_id'] == 1) || ($_SESSION['user_id'] == 2)) {
$current = $_POST['current'];
for ($i=1;$i<=5;$i++){
if ($_POST['current_'.$i]) == "on")
mysql_query("update footer_logos SET visible = 'Y' where id={$i}");
}
if (!mysql_query($query)) {
// The code, if the query not executed..
echo 'query was not executed';
}
}
}
if ($result = mysql_query($query)) { // Everything Worked.
echo $query;
echo '<div class="success"><b>Footer Logos updated !</b>';
echo '<p>The Footer Logos have been updated on the database.</p></div><br />';
echo '<ul><li><a href="index.php">Go back to Admin</a></li>';
echo '<li><a href="javascript:history.go(-1)">Go back to the previous page</a></li></ul>';
include ('../include/afootit.html');
exit;
}
else {
echo 'Error!';
// echo '<br />Sorry, you have to be one of the main Administrators to make changes here.<br />';
trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
}
}
$query1 = "SELECT * FROM footer_logos";
$result1 = @mysql_query($query1); // Run the Query.
echo '<p><b>Edit "Footer Logos"</b></p>';
echo $_POST['current'];
echo '<form name="form1" method="POST" action="update_logos.php" class="book">';
echo '<table width="550" border="0" style="padding:5px">';
echo '<tr style="background-color:#eaeaea;">
<td>Visible</td>
<td>Image</td>
<td>Link</td>
<td>ALT Text</td>
</tr>';
while ($row1 = mysql_fetch_assoc($result1)) { // use assoc, not array
if ($row1['visible']=='Y')
$checked="checked";
else
$checked="";
// use id to name each one differently
echo "<tr>
<td><input type='checkbox' name='current_{$row1['id']}' id='current_{$row1['id']}' value='{$row1['id']}' class='maillistadd' {$checked} /></td>
<td><img src='../images/{$row1['src']}' /></td><td>{$row1['link']}</td><td>{$row1['alt']}</td>
</tr>";
}
echo '</table>';
?>
<br>
<input name="submit" type="submit" class="submit" value="Update the 'Logos' box">
<br>
<br>
<input type="hidden" value="form1">
<input type="hidden" name="submitted" value="TRUE" />
</p>
</form>
<hr size="2" />
Just to say again, this form is used so that a user can check/uncheck checkboxes which will then update the table in my database to either make the value in the visible field, 'Y'(when checked) or 'N'(unchecked).
Right now I'm getting an error from the piece BlueKai gave me with the FOR Loop.
Any help would be brilliant.