Hi everyone,
Below is the index.php and voted.php file I am using. The user votes on the images, it passes the votes to the voted.php file and adds the tally to the database columns, and sends the user back to the index.php page. My question is this:
Once the person votes and is taken back to the index.php file, how can I have it display the results from the previous three images?
Here's my index.php code
<?php
// Connects to your Database
$link = mysql_connect('localhost', 'username', 'password');
mysql_select_db("database") or die(mysql_error());
?>
<?php include('header.php'); ?>
<div class="contentwide">
<div class="contentwrap">
<form method="post" action="voted.php">
<?php
$query = "SELECT id, name, url FROM photos WHERE category!= 'Xrated' ORDER BY RAND() LIMIT 3";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
?>
<input type="hidden" name="id[]" value="<?php echo $row['id']; ?>">
<input type="hidden" name="page" value="index.php">
<div class="picturewrap">
<img src="<?php echo $row['url']; ?>" alt="<?php echo $row['name']; ?>" />
<div class="formwrapper">
<div class="formspoon">
<img src="images/form_spoon.jpg" alt="" /><br />
<input type="radio" name="images[<?php echo $row['id']; ?>]" value="1">
</div>
</div>
<div class="formwrapper">
<div class="formspoon">
<img src="images/form_knife.jpg" alt="" /><br />
<input type="radio" name="images[<?php echo $row['id']; ?>]" value="3">
</div>
</div>
<div class="formwrapper">
<div class="formspoon">
<img src="images/form_fork.jpg" alt="" /><br />
<input type="radio" name="images[<?php echo $row['id']; ?>]" value="2">
</div>
</div>
</div>
<?php
}
?>
<div class="submitform">
<input type="image" src="images/button_submit.jpg" class="button_submit" value="Submit"><br/ >
</div>
</form>
</div>
</div>
<?php mysql_close($link); ?>
<?php include('footer.php'); ?>
Here is my voted.php file
<?php
// Connects to your Database
$link = mysql_connect('localhost', 'user', 'password');
mysql_select_db("database") or die(mysql_error());
$page = $_POST['page'];
if ( !empty( $_POST['images'] ) ) {
$images = $_POST['images'];
// Loop over each item in the $images array.
foreach ( $images as $id => $vote ) {
if ( $vote == 1 ) {
$update = sprintf( "UPDATE photos SET spoon=spoon+1 WHERE id=$id", $vote , $id );
mysql_query( $update ) OR DIE( "error in query" );
header("Location: $page");
} elseif ( $vote == 2 ) {
$update = sprintf( "UPDATE photos SET fork=fork+1 WHERE id=$id", $vote , $id );
mysql_query( $update ) OR DIE( "error in query" );
header("Location: $page");
} elseif ( $vote == 3 ) {
$update = sprintf( "UPDATE photos SET knife=knife+1 WHERE id=$id", $vote , $id );
mysql_query( $update ) OR DIE( "error in query" );
header("Location: $page");
} else
die( "Invalid value passed as a vote." );
}
}
?>
Thanks for any help I can receive