|
|
|
|
![]() ![]() |
Dec 1 2006, 09:14 AM
Post
#1
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 31 Joined: 9-August 06 Member No.: 28,049 |
Can somebody help me in creating a very simple javascript.. for example, the following code is example to delete a row from mysql.. all i want to do is.. that, when i click on delete, it gives a popup window , asking me if i really want to delete the row.. if i say Yes then it takes the action.. but if i say no then it takes back.'
CODE $result = mysql_query("select * from comments order by id desc limit 10");
//the while loop while($r=mysql_fetch_array($result)) { //getting each variable from the table $id = $r["id"]; $self = $_SERVER['PHP_SELF']; echo $r["comment"]; echo "<br />"; echo "<a href = \"$self?id=$id\">delete</a>"; } if(isset $_GET['id'])) { $id = $_GET['id']; // --------- here code to connect to mysql and select database ----------- $query= mysql_query("delete FROM comment where id =$id")or die(mysql_error()); } |
|
|
|
Dec 1 2006, 01:18 PM
Post
#2
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,035 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
hey what code help are you after? Do you mean you want a javascript page which will give you a link/button to delete a row and then this page goes to a PHP script which carries out the action? OR do you want a javascript script to do the actual deleting?
I only ask because the code you posted is PHP and im confused! And what is the problem you're having? Is it that you simply need this script written or there is an error you are getting? If theres an error youre getting then post us the error and we can hopefully help |
|
|
|
Dec 1 2006, 05:55 PM
Post
#3
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 138 Joined: 30-September 06 From: Iasi, Romania Member No.: 30,851 |
QUOTE if(window.confirm("Are you sure?")) {//redirect to your delete file} else {//write an error message or whatever} This will pop a dialog box with options "OK" and "Cancel"...hope its ok for what you need..write it as a function, then call the function in a link..or whatever, I think you can handle..I`m not too good at JS either, I handle ok php, html, css, but NOT javascript This post has been edited by hts: Dec 1 2006, 06:02 PM |
|
|
|
Dec 3 2006, 08:32 AM
Post
#4
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 181 Joined: 22-February 06 Member No.: 19,007 |
i guess i replied to a previous post of yours about deleting a particular row, since now you want a confirmation box i might as well suggest you to use another page to handle deleting, it will make life easy for you and you will understand it better i hope, so now we got to make some more modifications to the code , first put the following code in your original page where delete link is :
CODE <a href="java script:doConfirmation('<?=$content_id;?>','<?=$content_title?>')">delete</a> and put this in head section of your script : CODE <script language="JavaScript"> function doConfirmation(content_id,content_title) { if (confirm("Are you sure you want to delete " +content_title+ " ?")) { window.location="delete.php?id="+content_id; } } </SCRIPT> now in make another page called delete.php and put the following code : CODE ?> ob_start(); if(isset $_GET['id'])) { $id = $_GET['id']; // --------- here code to connect to mysql and select database ----------- $query= mysql_query("delete FROM comment where id =$id")or die(mysql_error()); header("location:some.php?action=deleted"); } ?> if you have any doubts please post back |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 7th October 2008 - 12:12 AM |