|
|
|
แก้ไขข้อมูลไม่ได้รบกวนช่วยตรวจสอบโค้ดให้หน่อยค่ะ ไม่รู้ว่ามีตรงไหนผิดหาไม่เจอค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php require_once('../Connections/MyConnec.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE student SET St_id=%s, St_User=%s, St_name=%s, St_surname=%s, St_Grop=%s, name_fac=%s, name_bra=%s WHERE St_sex=%s",
GetSQLValueString($_POST['St_id'], "text"),
GetSQLValueString($_POST['St_User'], "text"),
GetSQLValueString($_POST['St_name'], "text"),
GetSQLValueString($_POST['St_surname'], "text"),
GetSQLValueString($_POST['St_Grop'], "text"),
GetSQLValueString($_POST['name_fac'], "text"),
GetSQLValueString($_POST['name_bra'], "text"),
GetSQLValueString($_POST['St_sex'], "int"));
mysql_select_db($database_MyConnec, $MyConnec);
$Result1 = mysql_query($updateSQL, $MyConnec) or die(mysql_error());
$updateGoTo = "Student_Information.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE student SET St_id=%s, St_User=%s, St_name=%s, St_surname=%s, St_Grop=%s, name_fac=%s, name_bra=%s WHERE St_sex=%s",
GetSQLValueString($_POST['St_id'], "text"),
GetSQLValueString($_POST['St_User'], "text"),
GetSQLValueString($_POST['St_name'], "text"),
GetSQLValueString($_POST['St_surname'], "text"),
GetSQLValueString($_POST['St_Grop'], "text"),
GetSQLValueString($_POST['name_fac'], "text"),
GetSQLValueString($_POST['name_bra'], "text"),
GetSQLValueString($_POST['St_sex'], "int"));
mysql_select_db($database_MyConnec, $MyConnec);
$Result1 = mysql_query($updateSQL, $MyConnec) or die(mysql_error());
$updateGoTo = "Student_Information.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_GET['St_id'])) {
$colname_Recordset1 = $_GET['St_id'];
}
mysql_select_db($database_MyConnec, $MyConnec);
$query_Recordset1 = sprintf("SELECT * FROM student WHERE St_id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $MyConnec) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="for_admin.php">รายชื่อผู้ใช้งาน</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="for_admin.php">Home</a></li>
<li><a href="Student_Information.php">ผู้ใช้งาน</a></li>
<li><a href="subject.php">รายวิชา</a></li>
<li><a href="report.php">ออกรายงาน</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="index.php"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
</ul>
</div>
</nav>
<p> </p>
<div class="row">
<div class="col-sm-4"></div>
<div class="row">
<div class="col-xs-4">
</div>
</div>
</div>
<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">ลำดับ ::</td>
<td><input type="text" name="St_id" class="form-control" value="<?php echo htmlentities($row_Recordset1['St_id'], ENT_COMPAT, 'utf-8'); ?>"size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">รหัสนักศึกษา ::</td>
<td><input type="text" name="St_User" class="form-control" value="<?php echo htmlentities($row_Recordset1['St_User'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ชื่อ ::</td>
<td><input type="text" name="St_name" class="form-control" value="<?php echo htmlentities($row_Recordset1['St_name'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">นามสกุล ::</td>
<td><input type="text" name="St_surname" class="form-control" value="<?php echo htmlentities($row_Recordset1['St_surname'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">กลุ่มเรียน ::</td>
<td><input type="text" name="St_Grop" class="form-control" value="<?php echo htmlentities($row_Recordset1['St_Grop'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">คณะ ::</td>
<td><input type="text" name=" name_fac" class="form-control" value="<?php echo htmlentities($row_Recordset1['name_fac'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">สาขา ::</td>
<td><input type="text" name="name_bra" class="form-control" value="<?php echo htmlentities($row_Recordset1['name_bra'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">เพศ ::</td>
<td><input type="text" name="St_sex" class="form-control" value="<?php echo htmlentities($row_Recordset1['St_sex'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><br><div align="center">
<input type="submit" class="btn btn-success" value="ตกลง" />
</div></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form2" />
<input type="hidden" name="St_id" value="<?php echo $row_Recordset1['St_id']; ?>" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2017-05-24 07:55:29 |
By :
Tarnikar |
View :
774 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอา code ใส่ Tag PHP ด้วยครับ จะได้เห็นบรรทัด...
--ปล.ส่วนตัวไม่เคยเขียน connect database ผ่านโปรแกรม dream รอท่านอื่นแนะนำครับ
|
|
|
|
|
Date :
2017-05-24 09:00:02 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เขียน Code ตามหนังสือ พอ Error ก็ไปกันไม่เป็น ผมถึงแนะนำหลายครั้งแล้วการเขียน Code ให้เริ่มต้นจากทำความเข้าใจมันก่อน
|
|
|
|
|
Date :
2017-05-25 04:43:53 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|