Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • update data using get method

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 380
    Answer it

    update and delete using get method
    i have this code to update data from my database
    i have no error reporting but he's not updating  any data
    can you help me with that  


    my database and my code

    -- ----------------------------------------------------------
    --

    1. Table structure for table `examinee`
    2. --
    3.  
    4. CREATE TABLE `examinee` (
    5. `examinee_id` int(10) UNSIGNED NOT NULL,
    6. `user_name` varchar(30) NOT NULL,
    7. `password` varchar(40) NOT NULL,
    8. `date_of_registration` datetime NOT NULL
    9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    10.  
    11. --
    12. -- Dumping data for table `examinee`
    13. --
    14.  
    15. INSERT INTO `examinee` (`examinee_id`, `user_name`, `password`, `date_of_registration`) VALUES
    16. (1, 'khalidswaisi', 'swaisi2016', '2016-03-23 00:00:00'),
    17. (2, 'user', 'user', '2016-04-10 16:38:00'),
    18. (3, 'mohammed', 'nasyia', '0000-00-00 00:00:00');
    19.  
    20. -- --------------------------------------------------------
    21.  
    22.  
    23. display page
    24.  
    25. <?php include ("connection.php"); ?>
    26.  
    27. <center><h2>Examinee List</h2></center>
    28. <table border="1" cellpadding = "0" cellspacing = "0" width = "700" align = "center">
    29. <thead>
    30. <th> </th>
    31. <th> </th>
    32. <th> </th>
    33. <th> </th>
    34. </thead>
    35. <?php
    36. $sql = mysqli_query ($link,"SELECT * FROM `examinee`") or die ();
    37. while ( $row = mysqli_fetch_assoc($sql)) {
    38. echo "<tr>
    39. <td>".$row['examinee_id']."</td>
    40. <td>".$row['user_name']."</td>
    41. <td>".$row['password']."</td>
    42. <td>".$row['date_of_registration']."</td>
    43. <td align = 'center'>
    44. <a href = 'examinee_Edit.php?examinee_id=$row[examinee_id]'>Update</a>
    45. <a href = 'examinee_Delete.php?examinee_id=$row[examinee_id]'> Delete</a>
    46. </td>
    47. </tr>";
    48. }
    49.  
    50. ?>
    51. </table>
    52.  
    53. </body>
    54.  
    55.  
    56. </html>
    57.  
    58. </body>
    59. </html>

     

    update page

    1. <?php include ("connection.php"); ?>
    2. <?php
    3. $msg = "";
    4. if (isset($_POST['update'])) {
    5. if(is_numeric($_POST['examinee_id'])){
    6. $examinee_id = mysqli_real_escape_string($link,htmlspecialchars($_POST['examinee_id']));
    7. $user_name = $_POST['user_name'];
    8. $password = $_POST['password'];
    9. $date_of_registration = $_POST['date_of_registration'];
    10. $sql = mysqli_query ($link,"UPDATE `examinee` SET
    11. `user_name`=[$user_name],
    12. `password`=[$password],
    13. `date_of_registration`=[$date_of_registration]
    14. WHERE `examinee_id` = $examinee_id ")
    15. ;
    16. header ("location : index.php");
    17. }
    18. }
    19. else
    20. {
    21. if(isset($_GET['examinee_id']) && is_numeric($_GET['examinee_id']) && $_GET['examinee_id'] > 0 ){
    22. $examinee_id=$_GET['examinee_id'] ;
    23.  
    24. $sql = mysqli_query ($link,"SELECT * FROM `examinee` WHERE `examinee_id`=$examinee_id ") ;
    25. while( $row = mysqli_fetch_assoc ($sql) ){
    26. $examinee_id = $row ['examinee_id'];
    27. $user_name = $row['user_name'];
    28. $password = $row['password'];
    29. $date_of_registration = $row['date_of_registration'];
    30. }
    31. }
    32.  
    33. }
    34. ?>
    35. <html dir="rtl">
    36. <head>
    37. <title> </title>
    38. <meta http-equiv ="content-type" content="text/html"; charset = utf8" />
    39. <meta http-equiv="refresh" content="30">
    40. <center><h3>Update</h3></center>
    41. <center><h3><a href="examinee_Search.php"> </a></h3></center>
    42.  
    43. </head>
    44.  
    45. <body>
    46.  
    47. <form method= "POST" action = "" >
    48. <table width = "400" align = "center" >
    49. <tr>
    50. <td> </td>
    51. <td><input type="text" name = "examinee_id" value="<?php echo $examinee_id ;?>" /></td>
    52. </tr>
    53. <tr>
    54. <td> </td>
    55. <td><input type="text" name = "user_name" value="<?php echo $user_name ;?>" /></td>
    56. </tr>
    57. <tr>
    58. <td> </td>
    59. <td><input type="text" name = "password" value="<?php echo $password ;?>" /></td>
    60. </tr>
    61. <tr>
    62. <td> </td>
    63. <td><input type="text" name = "date_of_registration" value="<?php echo $date_of_registration ;?>" /></td>
    64. </tr>
    65. <tr>
    66. <td><input type="submit" name = "update" value=" " /></td>
    67. </tr>
    68. <tr>
    69. <td><input type="hidden" name = "examinee_id" value="<?php echo $_GET['examinee_id']; ?>" /></td>
    70. </tr>
    71.  
    72. </table>
    73.  
    74. </form>
    75. </body>
    76. </html>

     

 1 Answer(s)

  • please try this code

    $sql = mysqli_query ($link,"UPDATE examinee SET user_name='".$user_name."', password='".$password."', date_of_registration='".$date_of_registration."' WHERE examinee_id = $examinee_id ");

    Explanation:you are using varchar datatype for stroing username, password, and date of registration in database. so the value should be in string format like 'username'.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: