vijayrami

form

Apr 17th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2. $con= mysqli_connect ("localhost","root","","");
  3. if (mysqli_connect_errno())
  4. {
  5. echo "Failure to connect Mysql".mysqli_connect_error();
  6. }
  7. mysqli_select_db ($con, "vijay_rami");
  8. if($_POST["submit"] == "add")
  9. {
  10. $quli = $_POST['quli'];
  11. if(is_array($_POST['quli'])){
  12. $a = serialize($_REQUEST['quli']);
  13. $sql= "INSERT INTO studentdata (firstname,lastname,gender,qulification,address,city,country) VALUES ('".$_POST['fname']."','".$_POST['lname']."','".$_POST['gr']."','$a','".$_POST['address']."','".$_POST['city']."','".$_POST['country']."')";
  14. }
  15. $result=mysqli_query($con,$sql);
  16. if ($result)
  17. echo "Data Inserted Successfully";
  18. else
  19. echo "Error in inserting Data";
  20. }
  21. if ($_GET["action"] == "delete")
  22. {
  23. $result = mysqli_query ($con,"DELETE FROM studentdata WHERE id='".$_GET['id']."'");
  24. if ($result)
  25. echo "Data Deleted Successfully";
  26. else
  27. echo "Error In Deleting Data";
  28. }
  29. if ($_POST['submit'] == "edit")
  30. {
  31. $quli = $_POST['quli'];
  32. if(is_array($quli)){
  33. $b = serialize($quli);
  34. $sql= "UPDATE studentdata SET firstname='".$_POST['fname']."',lastname='".$_POST['lname']."', gender='".$_POST["gr"]."',qulification='$b',address='".$_POST['address']."',city='".$_POST['city']."',country='".$_POST['country']."' WHERE id='".$_POST['id']."'";
  35. }
  36. $result = mysqli_query ($con,$sql);
  37. if ($result)
  38. echo "Succesfully updated into database";
  39. else
  40. echo "Error while updating into database!!!";
  41. }
  42. $result1= mysqli_query ($con,"SELECT * FROM studentdata ORDER BY id");
  43. ?>
  44. <table border='1'>
  45. <tr>
  46. <th>Id</th>
  47. <th>First name</th>
  48. <th>Last name</th>
  49. <th>Gender</th>
  50. <th>Qualification</th>
  51. <th>Address</th>
  52. <th>City</th>
  53. <th>Country</th>
  54. <th>edit</th>
  55. <th>delete</th>
  56.  
  57. </tr>
  58. <?while($student= mysqli_fetch_array ($result1))
  59. {?>
  60. <tr>
  61. <td><?=$student['id']?></td>
  62. <td><?=$student['firstname']?></td>
  63. <td><?=$student['lastname']?></td>
  64. <td><?=$student['gender']?></td>
  65. <td><?
  66. $qulif = $student['qulification'];
  67. $myquls = unserialize($qulif);
  68. for($i=0; $i < count($myquls); $i++){
  69. echo $myquls[$i].',';
  70. }
  71. ?></td>
  72. <td><?=$student['address']?></td>
  73. <td><?=$student['city']?></td>
  74. <td><?=$student['country']?></td>
  75. <td><a href="edit.php?action=edit&id=<?=$student['id']?>">Edit</a></td>
  76. <td><a href="form.php?action=delete&id=<?=$student['id']?>">Delete</a></td>
  77. </tr>
  78. <?}?>
  79. </table>
  80. <a href="dbform.php">Click To Add</a>
  81. <? mysqli_close($con);?>
Advertisement
Add Comment
Please, Sign In to add comment