Jump to content

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/196125-call-php-function-with-input-typeimage/
Share on other sites

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=""

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>

@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.

<?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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.