delete in javascript.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
athlhaz
Forum Newbie
Posts: 9
Joined: Fri Dec 23, 2011 12:00 am

delete in javascript.

Post by athlhaz »

how can i delete a row in mysql database using a javascript..? can anyone show me a example?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: delete in javascript.

Post by Christopher »

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)
noel001
Forum Newbie
Posts: 2
Joined: Tue Jan 10, 2012 2:53 am

Re: delete in javascript.

Post by noel001 »

Dear Friend
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;
}
}
Setup your page to look for $_GET['mode'] == "delete" and process your query:

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!";
}
Works very well for me!

Smith
eSparkInfo
athlhaz
Forum Newbie
Posts: 9
Joined: Fri Dec 23, 2011 12:00 am

Re: delete in javascript.

Post by athlhaz »

thx..
Post Reply