PHP Dropdown with Country State District through JavaScript

Normally In form country State District create in Ajax

In This case we have create in JavaScript

Create one file name as dynamic.php

<html>
<head>
<script type=”text/javascript”>

function p()   //when select contry this function exicute
{

var s1=document.getElementById(‘select1’).value;//get id of select1 tag
var s2=document.getElementById(‘select2’);//get id of select2 tag

if(s1 == “india”)
{
var state=[“Gujrat”,”MP”];
}
if(s1 == “canada”)
{
var state=[“TY”,”FGGH”];
}

for(var i=0;i<state.length;i++)
{

var newoption=document.createElement(“option”);//create option variable of select
newoption.value = state[i]; //set value of option
newoption.innerHTML = state[i]; //set tagname of option
s2.options.add(newoption); //add value and tag name of option

}

}
function p1()//when select state this function exicute
{

var s2=document.getElementById(‘select2’).value;
var s3=document.getElementById(‘select3’);

if(s2 == “Gujrat”)
{
var dis=[“Surat”,”Vapi”,”Baroda”];
}
if(s2 == “MP”)
{
var dis=[“Indor”,”Bhopal”];
}

for(var i=0;i<dis.length;i++)
{

var newoption=document.createElement(“option”);
newoption.value=dis[i];
newoption.innerHTML=dis[i];
s3.options.add(newoption);

}

}

</script>
</head>

<body>
<center>

<h2>Contry State District</h2>
<select id=”select1″ name=”select1″ onChange=”p()”>

<option value=””>Country</option>
<option value=”india”>India</option>
<option value=”canada”>Canada</option>

</select>
<select id=”select2″ name=”select2″ onChange=”p1()”>

<option value=””>State</option>

</select>
<select id=”select3″ name=”select3″>

<option value=””>District</option>

</select>

</center>
</body>
</html>

O/P

poi.png

PHP Conform message On press Delete button

Conform message is one of the JavaScript  feature ….

So,we use in php

First create tech_check_delete.php file

 

<html>
<body>

<table border=”1″>
<?php

$con=mysql_connect(‘localhost’,’root’,”);
if(!$con)
die(“not connected”.mysql_error());
echo “connected”.”<br>”;
mysql_select_db(‘db’);

$sql=”select * from tech;”;

$check=mysql_query($sql,$con);
if(!$check)

die(“not selected”.mysql_error());

echo “selected”;
while($row=mysql_fetch_array($check))
{

cho “<tr>”;
echo “<td> $row[0]</td>”;
echo “<td> $row[1]</td>”;

?>

<td>

<a href=’delete.php?id=<?php echo $row[0]?> onClick=”return confirm(‘are you sure?’);”>

<button>Delete</button></a>

</td>
<?php

echo “</tr>”;
}

?>

</table>
</body>
</html>

 

sec delete.php file

<html>
<body>

<?php

$con=mysql_connect(‘localhost’,’root’,”);
mysql_select_db(‘db’);

$id=$_REQUEST[‘id’];

$sql=”delete from tech where id=$id”;
mysql_query($sql,$con);

header(“location:tech_check_delete.php”);    //redirect on main page

?>

</body>
</html>

 

O/P

poi.png

PHP Update data from Mysql Database

For Updating purpose we have require 2 value,

new and old value for change

so,create update.php file and copy following code

<html>
<body>

<form action=”” method=”post”>
Enter existing email:<input type=”text” name=”e1″><br>
Enter new email: <input type=”text” name=”n1″><br>
<input type=”submit” name=”btn” value=”Update”><br>

<?php
include(‘connection.php’);
if(isset($_POST[‘btn’]))
{

$old=$_POST[‘e1’];
$new=$_POST[‘n1’];

$sql=”update login set email=’$new’ where email=’$old’;”;//update query

$check=mysql_query($sql,$con); //check query
if(!$check)
{
die(“Data not update”.mysql_error());
}
echo “Data updated”;

}
?>

</form>
</body>
</html>

O/P

=>First 3 data available in table

poi.png

=>Update email field there old value abc and new value is xyz

poi.png

=>After update table situation

poi.png

 

 

Comments

PHP Delete data from Mysql Database

<html>
<body>

<form action=”” method=”post”>
Enter id:<input type=”text” name=”id”><br>
<input type=”submit” name=”btn”>
</form>

<?php

include(‘connection.php’);

if(isset($_POST[‘btn’]))
{

$id=$_POST[‘id’];

$sql=”delete from login where id=$id;”;
$check=mysql_query($sql,$con);

if(!$check)
{
die(“Data not delete”.mysql_error());
}

echo “Delete data..”;

}

?>

</body>
</html>

O/p:

=>This data available in our table

cpp.png

=>Delete data from coding

cpp.png

=>After deleting situation of table

cpp.png