Judul : JAVASCRIPT CODE FOR CONFIRMATION BEFORE DELTE A RECORD
link : JAVASCRIPT CODE FOR CONFIRMATION BEFORE DELTE A RECORD
JAVASCRIPT CODE FOR CONFIRMATION BEFORE DELTE A RECORD
NOW LEARN HOW TO USE YES NO CONFIRMATION CODE OF JAVASCRIPT WITH PHP SCRIPT TO ASK FOR CONFIRMATION BEFORE DELTE A RECORD :
========================================================================
(1)create a database ajax and then create a table users :
SQL>
CREATE TABLE users (
user_id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
first_name VARCHAR( 25 ) NOT NULL ,
last_name VARCHAR( 25 ) NOT NULL ,
user_city VARCHAR( 45 ) NOT NULL
);
insert at least 5 records into your table and then
(2)then write code for index.php file:
<html>
<head>
<script type="text/javascript">
function delete_id(id)
{
if(confirm('Sure To Remove This Record ?'))
{
window.location.href='index.php?delete_id='+id;
}
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("ajax");
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
?>
<table align="center">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>Delete</th>
</tr>
<?php
if(mysql_num_rows($result_set)>0)
{
while($row=mysql_fetch_row($result_set))
{
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td align="center"><a href="javascript:delete_id(<?php echo $row[0]; ?>)"><img src="b_drop.png" alt="Delete" /></a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<th colspan="4">There's No data found !!!</th>
</tr>
<?php
}
?>
</table>
<?php
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM users WHERE user_id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: index.php");
}
?>
now get understanding about above code:
NOW LEARN HOW TO USE YES NO CONFIRMATION CODE OF JAVASCRIPT WITH PHP SCRIPT TO ASK FOR CONFIRMATION BEFORE DELTE A RECORD :
<html>
<head>
<script type="text/javascript">
function delete_id(id)
{
if(confirm('Sure To Remove This Record ?'))
{
window.location.href='index.php?delete_id='+id;
}
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("ajax");
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
?>
<table align="center">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>Delete</th>
</tr>
<?php
if(mysql_num_rows($result_set)>0)
{
while($row=mysql_fetch_array($result_set))
{
?>
<tr>
<td><?php echo $row['user_id']; ?></td>
<td><?php echo $row['first_name']; ?></td>
<td><?php echo $row['last_name']; ?></td>
<td align="center"><a href="javascript:delete_id(<?php echo $row['user_id']; ?>)"><img src="b_drop.png" alt="Delete" /></a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<th colspan="4">There's No data found !!!</th>
</tr>
<?php
}
?>
</table>
<?php
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM users WHERE user_id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: index.php");
}
?>
(1)create a database ajax and then create a table users :
SQL>
CREATE TABLE users (
user_id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
first_name VARCHAR( 25 ) NOT NULL ,
last_name VARCHAR( 25 ) NOT NULL ,
user_city VARCHAR( 45 ) NOT NULL
);
insert at least 5 records into your table and then
(2)then write code for index.php file:
<html>
<head>
<script type="text/javascript">
function delete_id(id)
{
if(confirm('Sure To Remove This Record ?'))
{
window.location.href='index.php?delete_id='+id;
}
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("ajax");
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
?>
<table align="center">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>Delete</th>
</tr>
<?php
if(mysql_num_rows($result_set)>0)
{
while($row=mysql_fetch_row($result_set))
{
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td align="center"><a href="javascript:delete_id(<?php echo $row[0]; ?>)"><img src="b_drop.png" alt="Delete" /></a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<th colspan="4">There's No data found !!!</th>
</tr>
<?php
}
?>
</table>
<?php
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM users WHERE user_id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: index.php");
}
?>
now get understanding about above code:
following is the anchor link that call the below javascript function.
<a href="javascript:delete_id(<?php echo $row[0]; ?>)">Delete</a>
put the following javascript just above your closing </head> tag
<script type="text/javascript">
function delete_id(id)
{
if(confirm('Sure To Remove This Record ?'))
{
window.location.href='index.php?delete_id='+id;
}
}
</script>
window.location.href='index.php?delete_id='+id; This javascript object creates the QueryString like index.php?delete_id=any_value
and the rest of work is php if the querystring is set the selected row will be deleted using following php condition.
and the rest of work is php if the querystring is set the selected row will be deleted using following php condition.
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM users WHERE user_id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: index.php");
}
NOW LEARN HOW TO USE YES NO CONFIRMATION CODE OF JAVASCRIPT WITH PHP SCRIPT TO ASK FOR CONFIRMATION BEFORE DELTE A RECORD :
========================================================================
(1)create a database ajax and then create a table users :
SQL>
CREATE TABLE users (
user_id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
first_name VARCHAR( 25 ) NOT NULL ,
last_name VARCHAR( 25 ) NOT NULL ,
user_city VARCHAR( 45 ) NOT NULL
);
(1)create a database ajax and then create a table users :
SQL>
CREATE TABLE users (
user_id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
first_name VARCHAR( 25 ) NOT NULL ,
last_name VARCHAR( 25 ) NOT NULL ,
user_city VARCHAR( 45 ) NOT NULL
);
<html>
<head>
<script type="text/javascript">
function delete_id(id)
{
if(confirm('Sure To Remove This Record ?'))
{
window.location.href='index.php?delete_id='+id;
}
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("ajax");
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
?>
<table align="center">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>Delete</th>
</tr>
<?php
if(mysql_num_rows($result_set)>0)
{
while($row=mysql_fetch_array($result_set))
{
?>
<tr>
<td><?php echo $row['user_id']; ?></td>
<td><?php echo $row['first_name']; ?></td>
<td><?php echo $row['last_name']; ?></td>
<td align="center"><a href="javascript:delete_id(<?php echo $row['user_id']; ?>)"><img src="b_drop.png" alt="Delete" /></a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<th colspan="4">There's No data found !!!</th>
</tr>
<?php
}
?>
</table>
<?php
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM users WHERE user_id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: index.php");
}
?>
Demikianlah Artikel JAVASCRIPT CODE FOR CONFIRMATION BEFORE DELTE A RECORD
Sekianlah artikel JAVASCRIPT CODE FOR CONFIRMATION BEFORE DELTE A RECORD kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel JAVASCRIPT CODE FOR CONFIRMATION BEFORE DELTE A RECORD dengan alamat link https://othereffect.blogspot.com/2016/12/javascript-code-for-confirmation-before.html
0 Response to " JAVASCRIPT CODE FOR CONFIRMATION BEFORE DELTE A RECORD "
Post a Comment