delete in javascript.
Moderator: General Moderators
delete in javascript.
how can i delete a row in mysql database using a javascript..? can anyone show me a example?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: delete in javascript.
On the Javascript look into Ajax calls to PHP. On the PHP site, see the documentation for your database adapter about using the SQL DELETE command.
(#10850)
Re: delete in javascript.
Dear Friend
set your link as follows:
Setup your page to look for $_GET['mode'] == "delete" and process your query:
Works very well for me!
Smith
eSparkInfo
set your link as follows:
Code: Select all
<a href="?mode=delete&record_id=[your record id]" onclick="return rem()">delete</a>
Setup your java script:
function rem(){
if(confirm('Are you sure you want to delete this record?\nNo going back!')){
return true;
}else{
return false;
}
}Code: Select all
if(isset($_GET['mode']) && $_GET['mode']=="delete"){
$id = (int) $_GET['record_id'];
mysql_query("DELETE FROM table_name WHERE id = " . $id . " LIMIT 1");
mysql_query("OPTIMIZE TABLE table_name");
echo "Record deleted successfully!";
}
Smith
eSparkInfo