Page 1 of 1

delete in javascript.

Posted: Mon Jan 02, 2012 5:08 am
by athlhaz
how can i delete a row in mysql database using a javascript..? can anyone show me a example?

Re: delete in javascript.

Posted: Tue Jan 03, 2012 12:47 am
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.

Re: delete in javascript.

Posted: Wed Jan 11, 2012 4:14 am
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

Re: delete in javascript.

Posted: Tue Jan 17, 2012 7:59 am
by athlhaz
thx..