Monday, September 26, 2016

php Demo

Config code
==========
<?php
mysql_connect("localhost","root","");
mysql_select_db("studentreg");
?>


===============================================
Index
============


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Student Info.</title>
</head>

<body>
<?php
if(isset($_REQUEST['demo'])=="insret")
{
echo "Record Insert Successfully";
}

?>

<form method="post" action="insert.php" enctype="multipart/form-data">
<h1 style="color:#990000" align="center">Student Registration Form<h1>

<table align="center">
<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Name:</td>
<td><input type="text" size="40px" name="name" style="border-color:#9999FF"/></td>
</tr>

<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Address:</td>
<td><input type="text" size="40px" name="address" style="border-color:#9999FF"/></td>
</tr>

<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Roll No:</td>
<td><input type="text" size="40px" name="number" style="border-color:#9999FF"/></td>
</tr>

<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">E-mail Id:</td>
<td><input type="text" size="40px" name="EmailId" style="border-color:#9999FF"/></td>
</tr>

<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Mo. No:</td>
<td><input type="text" size="40px" name="monumber" style="border-color:#9999FF"/></td>
</tr>

<tr>
        <td width="150px" style="align:right; font-size:24px; color:#333333; text-align:right">State:</td>
            <td width="300px"><select name="state" id="state" title="state">
            <option name="Plz select" value="0">Plz Select State</option>
                                <option>Gujarat</option>
                                <option>Delhi</option>
                                <option>Mumbai</option>
                                </select></td>
         
                </tr>



<tr>
      <td width="150px" style="text-align:right; font-size:24px; color:#333333">Gender:</td>
        <td width="100px" style="text-align:left; font-size:14px">
        <input type="radio" name="radiobtn"  value="male" checked="checked" style="font-size:12px"/>Male
        <input type="radio" name="radiobtn"  value="female"  />Female
   </td>
</tr>

<tr>
        <td width="150px" style="text-align:right; font-size:24px; color:#333333">Hobbies:</td>
            <td width="100px" style="text-align:left; font-size:14px">
            Reading:<input type="checkbox" name="chkbox[]"  value="reading"/>
            Writing: <input type="checkbox" name="chkbox[]"  value="writing"  />
            </td>
         
</tr>

<tr>
        <td width="150px" style="text-align:right;font-size:24px;color:#333333">Photo:</td>
            <td width="100px"><input type="file" name="file"/></td>
         
</tr>

<tr>
<td colspan="2" align="center"><input type="submit" value="submit" name="btnsubmit"/>
</td>
</tr>
</table>

</form>
<br /><br />


<?php
include 'config.php';
$sql=mysql_query("select * from data");
?>

<table align="center" border="1">
<tr>
    <th style="color:#666666; font-size:15px">Id</th>
    <th style="color:#666666; font-size:15px">Name</th>
    <th style="color:#666666; font-size:15px">Address</th>
    <th style="color:#666666; font-size:15px">Roll No.</th>
     <th style="color:#666666; font-size:15px">E-mail ID</th>
    <th style="color:#666666; font-size:15px">Mobile No.</th>
    <th style="color:#666666; font-size:15px">State</th>
    <th style="color:#666666; font-size:15px">Gender</th>
    <th style="color:#666666; font-size:15px">Hobby</th>
    <th style="color:#666666; font-size:15px">Photo</th>
    <th style="color:#666666; font-size:15px">Edit</th>
    <th style="color:#666666; font-size:15px">Delete</th>
 
 
</tr>

<?php
while($row=mysql_fetch_array($sql))
{
?>

<tr align="left" style="font-size:14px; color:#006699">

<td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><?php echo $row[5]; ?></td>
<td><?php echo $row[6]; ?></td>
<td><?php echo $row[7]; ?></td>
<td><?php echo $row[8]; ?></td>

<td><img src="upload/<?php echo $row[9];?>" width="50" height="50" /></td>
<td><a href="edit.php?id=<?php echo $row[0]; ?>">Edit</a></td>
<td><a href="delete.php?id=<?php echo $row[0]; ?>">delete</a></td>

</tr>

<?Php
}
?>


</body>
</html>

========================================================================

Insert
==========
<?php
include 'config.php';

if(isset($_POST['btnsubmit']))
{
$name=$_POST['name'];
$address=$_POST['address'];
$number=$_POST['number'];
$EmailId=$_POST['EmailId'];
$monumber=$_POST['monumber'];
$state=$_POST['state'];
$radiobtn=$_POST['radiobtn'];
$hobby=implode(",",$_POST['chkbox']);
$fname=$_FILES['file']['name'];
$ftmpname=$_FILES['file']['tmp_name'];
move_uploaded_file($ftmpname,'upload/' .$fname);
$sql=("insert into data (name,address,rollno,emailid,mobno,state,gender,hobby,photo)values('$name','$address','$number','$EmailId','$monumber','$state','$radiobtn','$hobby','$fname')");
mysql_query($sql);
echo "<script>alert('added successfully')</script>";
header('location:index.php?demo=insert');


}
?>


===========================================================

delete
============
<?php
include 'config.php';
$id=$_REQUEST['id'];
mysql_query("delete from data where id='$id'");
header('location:index.php');
?>

=======================================================
edit
====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include 'config.php';
$id=$_REQUEST['id'];
$sql=mysql_query("select * from data where id='$id'");

while($row=mysql_fetch_array($sql))
{
$id=$row[0];
        $name=$row[1];
        $address=$row[2];
        $rollno=$row[3];
        $emailid=$row[4];
$mobileno=$row[5];
        $state=$row[6];
        $gender=$row[7];
        $hobby=explode(",",$row[8]);
        $photo=$row[9];
        
}
if(isset($_POST['btnsubmit']))
{
$name1=$_POST['name'];
$address1=$_POST['address'];
$rollno1=$_POST['number'];
$emailid1=$_POST['EmailId'];
$mobileno1=$_POST['monumber'];
$state1=$_POST['state'];
$gender1=$_POST['rbt'];
$hobby1=implode(",",$_POST['chkbox']);
if($_FILES['file']['name'] !=""){
$filename1=$_FILES['file']['name'];
}
$filetmpname1=$_FILES['file']['tmp_name'];
move_uploaded_file($filetmpname1,"upload/".$filename1);
mysql_query("update data set name='$name1',address='$address1',rollno='$rollno1',emailid='$emailid1',mobno='$mobileno1',state='$state1',gender='$gender1',hobby='$hobby1',photo='$filename1'
where id='$id'");
header('location:index.php');
}
?>
<form method="post" action="" enctype="multipart/form-data">
<h1 style="color:#990000" align="center">Student Registration Form<h1>

<table align="center">
<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Name:</td>
<td><input type="text" size="40px" name="name" style="border-color:#9999FF" value="<?php echo $name; ?>"/></td>
</tr>

<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Address:</td>
<td><input type="text" size="40px" name="address" style="border-color:#9999FF" value="<?php echo $address; ?>"/></td>
</tr>

<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Roll No:</td>
<td><input type="text" size="40px" name="number" style="border-color:#9999FF" value="<?php echo $rollno; ?>"/></td>
</tr>
<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">E-mail Id:</td>
<td><input type="text" size="40px" name="EmailId" style="border-color:#9999FF" value="<?php echo $emailid; ?>"/></td>
</tr>

<tr>
<td width="150px" style="font-size:24px; color:#333333" align="right">Mo. No:</td>
<td><input type="text" size="40px" name="monumber" style="border-color:#9999FF" value="<?php echo $mobileno; ?>"/></td>
</tr>

<tr>
<td width="150px" style="align:right; font-size:24px; color:#333333; text-align:right">State:</td>
<td width="300px"><select name="state" id="state" title="state">
            <option name="Plz select" value="0">Plz Select State</option>
                                <option <?php if($state=="Gujarat"){echo 'selected';}?>>Gujarat</option>
                                <option <?php if($state=="Delhi"){echo 'selected';}?>>Delhi</option>
                                <option <?php if($state=="Mumbai"){echo 'selected';}?>>Mumbai</option>
                                </select></td>
</tr>



<tr>
<td width="150px" style="text-align:right; font-size:24px; color:#333333">Gender:</td>
<td width="100px" style="text-align:left; font-size:14px">
<input type="radio" name="rbt"  value="male" style="font-size:12px" <?php if($gender=="male"){ echo 'checked'; }?>/>Male
<input type="radio" name="rbt"  value="female"  <?php if($gender=="female"){ echo 'checked'; }?>/>Female
</td>
</tr>

<tr>
        <td width="150px" style="text-align:right; font-size:24px; color:#333333">Hobbies:</td>
            <td width="100px" style="text-align:left; font-size:14px">
            Reading:<input type="checkbox" name="chkbox[]"  value="reading" <?php if(in_array("reading",$hobby)){echo 'checked';}?>/>
            Writing: <input type="checkbox" name="chkbox[]"  value="writing" <?php if(in_array("writing",$hobby)){echo 'checked';}?> />
            </td>
            
</tr>

<tr>
        <td width="150px" style="text-align:right;font-size:24px;color:#333333">Photo:</td>
            <td width="100px"><input type="file" name="file"/></td>
            
<td><img src="upload/<?php echo $photo;?>" width="50" height="50" /></td>
</tr>

<tr>
<td colspan="2" align="center"><input type="submit" value="submit" name="btnsubmit"/>
</td>
</tr>
</table>

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

No comments:

Post a Comment