mainstreetop Posted March 22, 2010 Share Posted March 22, 2010 Trying to call php function that execute's a mysql command via input type=image. I want the user to be able to click the image which adds an item to his 'My List' while remaining on the same page. This works in Chrome, but not in IE8. Does anyone have any ideas? I'm trying to avoid using $_GET. This is my test.php file: <?php if (isset($_POST['submit'])) { include('includes/dbconnect.php'); mysql_query ("INSERT INTO mylist VALUES ('','1','12345','')"); // redirect to avoid refresh adding duplicate entries header('Location: test.php'); } ?> <html> <body> <form action="<?php $php_self ?>" method="post"> <input type="image" name="submit" value="submit" src="images/mylist.jpg" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/196125-call-php-function-with-input-typeimage/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2010 Share Posted March 22, 2010 You will also find that it won't work in Opera. Read this recent thread - http://www.phpfreaks.com/forums/index.php/topic,291949.0.html You will also find that your action="...." attribute is not what you think (do a 'view source' in your browser.) You should just use an empty value to cause the page to submit to itself - action="" Quote Link to comment https://forums.phpfreaks.com/topic/196125-call-php-function-with-input-typeimage/#findComment-1030021 Share on other sites More sharing options...
l0ve2hat3 Posted March 22, 2010 Share Posted March 22, 2010 This should work... <?php if (isset($_POST['submit'])) { include('includes/dbconnect.php'); mysql_query ("INSERT INTO mylist VALUES ('','1','12345','')"); // redirect to avoid refresh adding duplicate entries header('Location: test.php'); } ?> <html> <body> <form name="form1" action="<?php $php_self ?>" method="post"> <input type="image" name="submit" value="submit" onclick="document.form1.submit();" src="images/mylist.jpg" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/196125-call-php-function-with-input-typeimage/#findComment-1030024 Share on other sites More sharing options...
mainstreetop Posted March 22, 2010 Author Share Posted March 22, 2010 @PFMaBiSmAd... Thank you for the link. I changed the $_POST['submit'] to $_POST['submit_x'] and the mysql query worked as hoped in IE8. I also noticed that removing the $php_self from the action='...' attribute does perform the same except that it leaves the '#' symbol in the url after clicking the image. Using the $php_self keeps the url clean. I know this may be a trivial matter, but does the '#' symbol in the url cause any other issues? @ l0ve2hat3... Thank you for your reply, too. I am going to use the first suggestion. I'm very new to all of this and it may be a little while before I become comfortable with JS. Quote Link to comment https://forums.phpfreaks.com/topic/196125-call-php-function-with-input-typeimage/#findComment-1030033 Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2010 Share Posted March 22, 2010 <?php $php_self ?> The above code is meaningless for two reasons. $php_self does not exist (unless you have some code you did not show) and you need to echo variables in order for the value in them to be output to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/196125-call-php-function-with-input-typeimage/#findComment-1030036 Share on other sites More sharing options...
mainstreetop Posted March 22, 2010 Author Share Posted March 22, 2010 No - I showed all the code. I understand what you are saying. I'm going to remove it. Thanks again for your help. I was stuck on this for quite some time. Quote Link to comment https://forums.phpfreaks.com/topic/196125-call-php-function-with-input-typeimage/#findComment-1030038 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.