Click to See Complete Forum and Search --> : Initiate query onClick


bhardin
01-08-2008, 09:11 PM
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:

<!--
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>


Thank you,
Conceptually Challenged Bill :confused:

novalys
01-09-2008, 02:55 AM
Well you could set the form action to target the same page, then add the php Script this way:


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


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


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


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

Good luck!

sekuchi
01-09-2008, 05:35 PM
Correct!!! Don't forget the isset() thing ok.

novalys
01-09-2008, 06:25 PM
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.

bhardin
01-09-2008, 06:32 PM
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).

novalys
01-09-2008, 11:08 PM
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

bhardin
01-11-2008, 11:18 AM
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

novalys
01-11-2008, 08:07 PM
Your welcome, have a nice weekend !

Jorge Limas.