page isn't updating when refreshed
Posted: Fri Apr 30, 2010 5:03 pm
Hi, I have a form which allows users to select a profile picture which is an animal. It uses <?php echo $_SERVER['PHP_SELF'] ?> because I want it to update the picture when the user hits submit, but for some reason it will only display the chosen picture if the user hits submit twice. However the database does update with the first hit of submit.
Here's the form...
This checks which picture number is stored in the database and displays the relevant image and the form if the picture number is 2 or 3 ( I realise this should probably be a switch statement):
and this updates the database with the selected image:
Not sure why it's not updating on first hit of submit...any ideas?
Thanks
Here's the form...
Code: Select all
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<br />Choose your profile picture or start looking after your pet horse<br />
Horse <input type="radio" name="1horse" value="1"/><br />
Cat <input type="radio" name="2cat" value="2"/><br />
Dog <input type="radio" name="3dog" value="3"/><br />
<input type="submit" name="pet_submit" />
</form>Code: Select all
// Collects data from "horse" table
$horse_profile_pic_query2 = mysql_query("SELECT * FROM users WHERE id='$member_id'")
or die(mysql_error());
// puts the "users" info into the an array
$horse_profile_pic_result2 = mysql_fetch_array( $horse_profile_pic_query2 );
if ( $horse_profile_pic_result2['profile_pic_id'] == 1) {
echo "<br /><br /><img src=\"a/images/1horse.jpg\" />";
} elseif ( $horse_profile_pic_result2['profile_pic_id'] == 2) {
echo "<br /><br /><img src=\"a/images/2cat.jpg\" /><br />";
include "a/inc/profile-pic-form.php";
} elseif ( $horse_profile_pic_result2['profile_pic_id'] == 3) {
echo "<br /><br /><img src=\"a/images/3dog.jpg\" />";
include "a/inc/profile-pic-form.php";
} else {
echo "<br /><br /><img src=\"a/images/7default.jpg\" /><br />";
include "a/inc/profile-pic-form.php";
}
Code: Select all
// if value is submitted insert into database
if (isset($_POST['1horse'])) {
//set $image to chosen value
$image = $_POST['1horse'];
//update $users table with chosen value
mysql_query("UPDATE users SET profile_pic_id = $image WHERE username = '$member_username'");
} elseif (isset($_POST['2cat'])) {
//set $image to chosen value
$image = $_POST['2cat'];
//update $users table with chosen value
mysql_query("UPDATE users SET profile_pic_id = $image WHERE username = '$member_username'");
} elseif (isset($_POST['3dog'])) {
//set $image to chosen value
$image = $_POST['3dog'];
//update $image table with chosen value
mysql_query("UPDATE users SET profile_pic_id = $image WHERE username = '$member_username'");
} Thanks