/    Sign up×
Community /Pin to ProfileBookmark

Initiate query onClick

Hello,

Can anyone steer me on a correct conceptual path for initiating a database query (a save from a temporary table to a permanent one) from the click of an HTML button? The only change I want on my page is for the button to disable after the query.

I present the code below in a storybook fashion for what I am trying to accomplish, and not in any serious way:

[CODE]
<!–
This navigation button appears on 4 different pages.
It is an include file on these 4 pages, and the query
should be able to be initiated only once from any of them.
–>
<table align=”center”>
<tr>
<td height=”80px”></td>
</tr>
<tr>
<td><input type=”button” name=”save” value=”Save”
onclick= <!– perform the query below –>
<?php
if (isset($id)) {
require_once (‘../mysql_connect.php’);
$query = “INSERT INTO table_permanent
SELECT NULL, first_name, last_name
FROM table_temporary
WHERE id=$id”;
mysql_query($query, $dbc);
}
?>
<!– After the query, the button should disable –>
</td>
</tr>
</table>
[/CODE]

Thank you,
Conceptually Challenged Bill ?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@novalysJan 09.2008 — Well you could set the form action to target the same page, then add the php Script this way:

[CODE]
if (isset($_POST['submit']))
{
Do the query thing....
}
[/CODE]


Also if you want to disable the button, you could add on the top of the page another

[CODE]
if (isset($_POST['submit']))
{
but instead of query set a Javacript to disable the submit button since
you already pressed once....
}
[/CODE]


Hope you did understand me.. and it helps, anyways.... I'll be around..

Good luck!
Copy linkTweet thisAlerts:
@sekuchiJan 09.2008 — Correct!!! Don't forget the isset() thing ok.
Copy linkTweet thisAlerts:
@novalysJan 10.2008 — Yes, just in case you don't know, isset checks if the variable exists if it does, it returns 1, else it returns 0....

Have a nice day, Jorge Limas.
Copy linkTweet thisAlerts:
@bhardinauthorJan 10.2008 — Thanks for the input. This takes my mind away from any AJAX solution, or such, and puts it back on a PHP path. I sorta, kinda thought in this direction, but it seemed funny to me to make a form for just this one button, which exists amongst a few others that are just hyperlinks. I should work though.

I'll post a solution when I get to this point. bh (Yes, isset() I'll remember).
Copy linkTweet thisAlerts:
@novalysJan 10.2008 — Actually there is another solution without Forms, you can also, make a page called, storeData.php or something, put the SQL query there, then from your original page you can make an onclick = saveData() on a hyperlink, then on your saveData() function make a window.open('storeData.php') and on the same function add the disable function for the button ! (Actually this solution is a little bit easier don't know why I told you the other one, sorry!

Have a nice day!!

Jorge.



PD. Forgot to tell, on the end of the storeData.php you can also have a window.close(), so the user doesnt need to close it :p
Copy linkTweet thisAlerts:
@bhardinauthorJan 11.2008 — Thanks for this last technique. I was having a little trouble switching back and forth between PHP and JavaScript in the first solution. This one looks cleaner, and I will give it a try soon.

Bill
Copy linkTweet thisAlerts:
@novalysJan 12.2008 — Your welcome, have a nice weekend !

Jorge Limas.
×

Success!

Help @bhardin 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 5.16,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...