Thursday 26 July 2012

update and delete record in php and mysql


update and delete record in php and mysql







Delete Record:



<html>
<head>
</head>

<body>
<table border="1" align="center">
<tr>
    <td>Id</td><td>Name</td><td>Delete</td><td>Update</td>
</tr>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test");

if(isset($_GET['id']))
{

    mysql_query("delete from stud where id=".$_GET['id']."");

?>
<script language="JavaScript">

window.location="dispaly.php";
</script>
<?php
}

$sql="select * from stud";
$qsql=mysql_query($sql);

while($row=mysql_fetch_array($qsql))
{
?>

<tr>
    <td><?php echo $row[0]; ?></td>
    <td><?php echo $row[1]; ?></td>
    <td><a href="dispaly.php?id=<?php echo $row[0]; ?>">Delete</a></td>
    <td><a href="update.php?uid=<?php echo $row[0]; ?>">Update</a></td>
</tr>

<?php

}


?>



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


update.php

<html>
<head>
</head>

<body>
<?php

$con=mysql_connect("localhost","root","");
mysql_select_db("test");

if(isset($_POST['submit']))
{

    $sql="update stud set name='".$_POST['txtnm']."',city='".$_POST['txtct']."' where id=".$_GET['uid']."";
    mysql_query($sql);
    ?>
   
    <?php

}


$sql="select * from stud where id=".$_GET['uid']."";
$qsql=mysql_query($sql);

$row=mysql_fetch_array($qsql)



?>

<form method="post">
<table border="1" align="center">
<tr>
    <td>Name:</td>
    <td><input type="text" name="txtnm" value="<?php echo $row['1']; ?>"></td>
</tr>

<tr>
    <td>City:</td>
    <td><input type="text" name="txtct" value="<?php echo $row['2']; ?>"></td>
</tr>

<tr>
    <td><input type="submit" name="submit" value="Update"></td>
    <td><input type="reset" name="reset" value="Cancle"></td>
</tr>


</table>

</form>

</body>
</html>

-->Main Page:











--->Update Page









demo of update and delete record in php and mysql

Thursday 19 July 2012

how to upload image in php



how to upload image in php 












upload.php
-------------------


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
$path="img/";
    //img   /----> you can specify the path where you can save image


$path=$path.basename($_FILES['img']['name']);


move_uploaded_file($_FILES['img']['tmp_name'],$path);
?>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="img">
<input type="submit" name="Upload" value="upload">

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


demo of how to upload image in php


Tuesday 17 July 2012

how to export and import database in mysql


1.Select your database from the list on the left.



2.Then Select On Export Tab and at the End Of Page Check on Save As file and  Select the File type and  Click on Go.








How to Import Database in Mysql.

 

1.Enter Database Name that you gave exported then click on create button.


2. Then Click on Import tab and browse the file using browse button.


3. After browsing the .sql file you have to click on Go button for import database.

 



 

Finally the Database is Imported..



 

 



Friday 13 July 2012

Displaying MySQL data in HTML tables in php


display.php

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table border="1" align="center">

<tr>
<td>Id</td><td>Name</td><td>City</td><td>Pincode</td>
</tr>
<?php

$con=mysql_connect("localhost","root","");
mysql_select_db("test");
$sql="select * from stud";
$nsql=mysql_query($sql);

while($row=mysql_fetch_array($nsql))
{
?>


    <tr>
        <td><?php echo $row[0];  ?></td>
        <td><?php echo $row[1];  ?></td>
        <td><?php echo $row[2];  ?></td>
        <td><?php echo $row[3];  ?></td>
   
    </tr>


<?php
}

?>

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

Monday 9 July 2012

Insert Record in Database Using Php , Mysql



















Insert.php


<html>
<head>
<title>Untitled Document</title>
</head>

<?php

$con=mysql_connect("localhost","root","");
mysql_select_db("demo");
echo $hb=$_POST['txtchk1']." ".$_POST['txtchk2']." ".$_POST['txtchk3'];

$sql="insert into stud(name,city,pincode,gender,hobby,branch,address)
values('".$_POST['fname']."','".$_POST['txtcity']."',".$_POST['pincode'].",'".$_POST['txtgen']."','".$hb."','".$_POST['txtbranch']."','".$_POST['txtadd']."')";

mysql_query($sql);

?>


<body>
<form method="post">
<table align="center" border="1">
    <tr>
   
        <td>First Name:</td>
        <td><input type="text" name="fname"></td>
    </tr>

<tr>

    <td>City:</td>
    <td><input type="text" name="txtcity"></td>

</tr>


<tr>
    <td>Pincode:</td>
    <td><input type="text" name="pincode"></td>

</tr>

<tr>

    <td>Gender:</td>
    <td>F:<input type="radio" name="txtgen" value="F">
   
        M:<input type="radio" name="txtgen" value="M">
    </td>

</tr>

<tr>
    <td>Hobby:</td>
    <td>
        Read:<input type="checkbox" name="txtchk1" value="Read">
        Playing:<input type="checkbox" name="txtchk2" value="Playing">
        Other:<input type="checkbox" name="txtchk3" value="Other">
    </td>

</tr>

<tr>
    <td>Branch:</td>
    <td>
        <select name="txtbranch">
        <option>BCA</option>
        <option>BIT</option>
        <option>PGDCA</option>
           
        </select>
   
    </td>

</tr>

<tr>
    <td>Address:</td>
    <td><textarea name="txtadd"></textarea> </td>

</tr>
<tr>
   
    <td><input type="submit" name="submit" value="Submit"></td>
    <td><input type="reset" name="reset" value="Cancle"></td>

</tr>
</table>

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