djexploit Posted December 8, 2013 Share Posted December 8, 2013 Hey there, I'm trying to make a simple point adding system and it works so far, but it works with a submit button and not an image. So if i click the button it will add 20 'points' to the database i provided but this does not seem to work with an image. Can someone help me with this, i'm kinda new to php. Code: <?php //defining username and amount of points to give + the current points $username = 'djexploit'; $seepoints = mysql_query("SELECT points FROM members WHERE username='$username'") or die(mysql_error()); $fetchresults = mysql_fetch_row($seepoints); $currentpoints = $fetchresults['0']; echo "Current points are: $currentpoints points."; $points = $currentpoints + 20 ; if(isset($_POST['submit'])) { $newpoints = $points; //the updating of the points field mysql_query("UPDATE `members` SET `points` = '$points' WHERE `username`= '$username'") or die(mysql_error()); echo "The amount of points has been updated. You now have $newpoints"; } else { echo '<br>click the image to add 20 points'; } ?> <html> <body> <form id="form" action="give.php" method="post"> <a href="http://www.google.com"><input type="image" src="http://hamovhotov.com/advertisement/wp-content/uploads/2007/03/468x60ad.gif" name="submit" value="submit"></a> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/ Share on other sites More sharing options...
MDCode Posted December 8, 2013 Share Posted December 8, 2013 Seeing as how you're wrapping it as a link... Not working isn't very specific as to what is not happening that should and what happens as it is now. Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461693 Share on other sites More sharing options...
djexploit Posted December 8, 2013 Author Share Posted December 8, 2013 it can only work if its src="example.png" ? Is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461695 Share on other sites More sharing options...
hitman6003 Posted December 9, 2013 Share Posted December 9, 2013 (edited) The HTML input tag does not have an image type that is also a submit button. http://www.w3schools.com/tags/tag_input.asp You could change the look of the button using CSS, or use javascript to submit the form when the image is clicked. Edited December 9, 2013 by hitman6003 Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461703 Share on other sites More sharing options...
hitman6003 Posted December 9, 2013 Share Posted December 9, 2013 The HTML input tag does not have an image type that is also a submit button. well...after further investigation, I appear to be wrong about that. I think the problem is that you are checking for "$_POST['submit']" to exist, but the image input type doesn't pass a value. Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461704 Share on other sites More sharing options...
djexploit Posted December 9, 2013 Author Share Posted December 9, 2013 Ah I see.. I thought that if ($_POST['submit]) meant if it was clicked. I don't know much about javascript although I did hear about OnClick() function. Could that be it? And if so how do i make it so that it posts to php so i can put it in an if statement? Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461706 Share on other sites More sharing options...
MDCode Posted December 9, 2013 Share Posted December 9, 2013 If it is the image submit problem and not that link to google around your image, use if($_SERVER['REQUEST_METHOD'] === "POST") { } instead Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461707 Share on other sites More sharing options...
djexploit Posted December 9, 2013 Author Share Posted December 9, 2013 @Socialcloud Thank you sir , the problem was the link around the image apparently, when i removed that it added points. But how do i make it so that it goes to a website and simultaneously adds points? Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461711 Share on other sites More sharing options...
MDCode Posted December 9, 2013 Share Posted December 9, 2013 The only way I can think of that working is to use JavaScript on submit which will never be universal as the user can just disable it. Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461718 Share on other sites More sharing options...
KevinM1 Posted December 9, 2013 Share Posted December 9, 2013 ...or, add the points, then redirect via headers? Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461721 Share on other sites More sharing options...
nodirtyrockstar Posted December 9, 2013 Share Posted December 9, 2013 (edited) The image should not affect your ability to submit. It is just a cosmetic feature. Looking into it now. Found a red herring and edited this post. Edited December 9, 2013 by nodirtyrockstar Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461735 Share on other sites More sharing options...
nodirtyrockstar Posted December 9, 2013 Share Posted December 9, 2013 (edited) I agree with previous commenters that it would help to know what your link does when you click on it. PLEASE don't use JavaScript. That is a hack. Try putting the type="submit" attribute on the input. The name attribute gives the element a name, and the value is the actual data you are passing. You should consider reading the API. MDN is better than w3schools.com. They're notoriously wrong.Here ya go: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/InputIf this works, please don't forget to mark my answer as the solution. (please) Edited December 9, 2013 by nodirtyrockstar Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461736 Share on other sites More sharing options...
djexploit Posted December 9, 2013 Author Share Posted December 9, 2013 Hmm i changed the type from 'image' to 'submit' but now it shows a submit button instead of the image.. Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461744 Share on other sites More sharing options...
MDCode Posted December 9, 2013 Share Posted December 9, 2013 You said the form had already been submitted correctly. You can use Kevin's advice and header after the processing is done, but it won't be simultaneous and will have them leave your page. The only way to do two windows is JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/284628-post-with-image-not-working/#findComment-1461772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.