/    Sign up×
Community /Pin to ProfileBookmark

Little help…

Hi guys,

I’ve got an image set as a submit button and im trying to change the submit button image so after its been clicked it changed to another image when the form is submitted the page is being sent to its self. The image doesn’t change until the button is pressed twice any ideas?? heres the code: –

[code=php]

<form action=”<?php echo “all_pics.php?id=$imgid”; ?>” method=”post”>

<?php

if ($check2 == 0) {

echo ‘<input type=”image” name=”submit1″ src=”like.png” border=”0″ value=”Like” />’;

}else {

echo “<img src=’thumbsup.png’/>”;

}
?>
</form>
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@chris22Apr 09.2010 — Hi, it might be because your images are cached by the browser, try appending a random string to src="..." url, for example:

[code=php]
if ($check2 == 0) {


echo '<input type="image" name="submit1" src="like.png?_dc='.time().'" border="0" value="Like" />';

}else {

echo "<img src='thumbsup.png?_dc=".time()."'/>";

}
[/code]


This way your images will never be cached locally.
Copy linkTweet thisAlerts:
@BIOSTALLApr 09.2010 — The PHP is determining which image to display before the images are even called by the browser so I don't think caching is your problem here.

Are you able to tell us how and where $check2 is being set?
Copy linkTweet thisAlerts:
@swl7authorApr 09.2010 — cheers for replying the time() didn't work...

heres the $check

[code=php]

$check = mysql_query("SELECT * FROM likes WHERE user='$_SESSION[email]' AND imgid='$imgid'")or die(mysql_error());

$check2 = mysql_num_rows($check);

[/code]
Copy linkTweet thisAlerts:
@OctoberWindApr 10.2010 — where in this process are you updating the 'likes' table with the $_SESSION['email'] and the $imgid association?

it might help to post the entire 'all_pics.php' page.
Copy linkTweet thisAlerts:
@BIOSTALLApr 10.2010 — Yes I can only think the issue is similar to what OctoberWind suggested; The SELECT statement you posted above is coming before you update the database from the initial click.
×

Success!

Help @swl7 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...