Advertisement
Haezz

editpeserta.php

Jul 12th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.29 KB | None | 0 0
  1. <?php require_once('Connections/connection.php'); ?>
  2. <?php
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  4. {
  5.   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  6.  
  7.   switch ($theType) {
  8.     case "text":
  9.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  10.       break;    
  11.     case "long":
  12.     case "int":
  13.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  14.       break;
  15.     case "double":
  16.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  17.       break;
  18.     case "date":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;
  21.     case "defined":
  22.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  23.       break;
  24.   }
  25.   return $theValue;
  26. }
  27.  
  28. $editFormAction = $_SERVER['PHP_SELF'];
  29. if (isset($_SERVER['QUERY_STRING'])) {
  30.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  31. }
  32.  
  33. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  34.   $updateSQL = sprintf("UPDATE peserta SET nama=%s,nokp=%s, jantina=%s, kelas=%s WHERE idpeserta=%s",
  35.                        GetSQLValueString($_POST['namapeserta'], "text"),
  36.                        GetSQLValueString($_POST['nokp'], "text"),
  37.                  GetSQLValueString($_POST['jantina'], "text"),
  38.                        GetSQLValueString($_POST['idkelas'], "text"),
  39.                        GetSQLValueString($_POST['idpeserta'], "text"));
  40.  
  41.   mysql_select_db($database_connection, $connection);
  42.   $Result1 = mysql_query($updateSQL, $connection) or die(mysql_error());
  43.  
  44.   if (isset($_SERVER['QUERY_STRING']))
  45.                     {
  46.                      echo "<script>alert('Record updated.')</script>";
  47.                      $GoTo = "paparpeserta.php";
  48.                     echo "<meta http-equiv='refresh' content='0;url=$GoTo'>";
  49.                     }
  50. }
  51.  
  52. if (isset($_GET['idpeserta']))
  53. {
  54.     $id = $_GET['idpeserta'];
  55. mysql_select_db($database_connection, $connection);
  56. $query_q_editpeserta = "SELECT peserta.idpeserta, peserta.nama, peserta.nokp, peserta.kelas, peserta.jantina, kelas.namakelas
  57. FROM peserta
  58. INNER JOIN kelas ON peserta.kelas = kelas.idkelas where peserta.idpeserta= $id";
  59. $q_editpeserta = mysql_query($query_q_editpeserta, $connection) or die(mysql_error());
  60. $row_q_editpeserta = mysql_fetch_assoc($q_editpeserta);
  61. $totalRows_q_editpeserta = mysql_num_rows($q_editpeserta);
  62.  
  63. }
  64. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  65. <html xmlns="http://www.w3.org/1999/xhtml">
  66. <head>
  67. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  68. <title>Untitled Document</title>
  69. <style type="text/css">
  70. <!--
  71. .style1 {font-size: 18px}
  72. -->
  73. </style>
  74. </head>
  75.  
  76. <body>
  77.  
  78. <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  79.   <table align="center">
  80.   <tr><th colspan="2">Kemaskini Data Peserta</th></tr>
  81.     <tr valign="baseline">
  82.       <td nowrap align="right">Idpeserta:</td>
  83.       <td><?php echo $row_q_editpeserta['idpeserta']; ?></td>
  84.     </tr>
  85.     <tr valign="baseline">
  86.       <td nowrap align="right">Nama:</td>
  87.       <td><input type="text" name="namapeserta" value="<?php echo $row_q_editpeserta['nama']; ?>" size="32"></td>
  88.     </tr>
  89.     <tr valign="baseline">
  90.       <td nowrap align="right">No KP:</td>
  91.       <td><input type="text" name="nokp" value="<?php echo $row_q_editpeserta['nokp']; ?>" size="32"></td>
  92.     </tr>
  93.     <tr valign="baseline">
  94.       <td nowrap align="right">Jantina:</td>
  95.       <td><input type="text" name="jantina" value="<?php echo $row_q_editpeserta['jantina']; ?>" size="32"></td>
  96.     </tr>
  97.     <tr valign="baseline">
  98.       <td nowrap align="right">Kelas:</td>
  99.       <td><input type="text" name="namakelas" value="<?php echo $row_q_editpeserta['namakelas']; ?>" size="32"><input type="hidden"name="idkelas" value="<?php echo $row_q_editpeserta['kelas']; ?>" /></td>
  100.     </tr>
  101.     <tr valign="baseline">
  102.       <td nowrap align="right">&nbsp;</td>
  103.       <td><input type="submit" value="Update record"></td>
  104.     </tr>
  105.   </table>
  106.   <input type="hidden" name="MM_update" value="form1">
  107.   <input type="hidden" name="idpeserta" value="<?php echo $row_q_editpeserta['idpeserta']; ?>">
  108. </form>
  109. <p>&nbsp;</p>
  110. </body>
  111. </html>
  112. <?php
  113. mysql_free_result($q_editpeserta);
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement