Jump to content

Update database with onClick function


Shamrox

Recommended Posts

I'm trying to update the status of a record in my database using onClick to call a function I wrote, but it doesn't seem to do anything. What am I doing wrong here?

Code for function:
[code]
function clear_record($id) {
$sql = "UPDATE`spec_registrar` SET `surveystatus`= 'clear' WHERE `registrarid` = '$id';";
}
[/code]

Code for calling it:
[code]
<input type="image" img src="images/admin_images/gridicon_delete.gif" alt="Clear from table" width="20" height="20" border="0"  onClick="clear_record(<?php echo $row_rs_survey['registrarid']; ?>);"/>
[/code]
Link to comment
Share on other sites

I'm not sure I completely understand what you are trying to do here...

Is the function clear_record() a PHP function?  If that is the case you can not execute that function from an onClick event.  The onClick event is a Javascript event, so you will need to use a Javascript function to trigger a remote PHP function.  This can be done in a number of ways.  You would use some sort of AJAX script, Javascript redirect (window.location=remote_url), or since you are using an input button you could simply submit the form to a remote PHP script.
Link to comment
Share on other sites

If you are just wanting to remove it from a table that is displayed on the screen you would need to use some Javascript to modify the DOM.  What is below is the basic structure of what you need.  You will need to modify it to work with your page layout.

element.removeChild(referenceToChildNode)
Link to comment
Share on other sites

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.