|
|
|
PHP Edit record ไม่มี error แต่ข้อมูลไม่ถูกบันทึกครับ ช่วยดูโค้ดให้หน่อยครับ |
|
|
|
|
|
|
|
File edit.php)
<?
session_start() ;
include("config.inc.php") ;
mysql_select_db($dbname) ;
$strSQL = "SELECT * FROM user WHERE UserID = '".$_SESSION['UserID']."' " AND "SELECT * FROM member WHERE id = '".$_SESSION['id']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>Shooter</TITLE><style type="text/css"></style>
<link href="css/master.css" rel="stylesheet" type="text/css"/>
<link href="calendar/calendar.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="calendar/calendar.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function checkdate(objName) {
var datefield = objName;
if (chkdate(objName) == false) {
datefield.select();
alert("ป้อน วัน เดือนปี ผิด ! โปรดป้อนใหม่");
datefield.focus();
return false;
}
else {
return true;
}
}
function chkdate(objName) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU"; //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "/01/";
strMonthArray[1] = "/02/";
strMonthArray[2] = "/03/";
strMonthArray[3] = "/04/";
strMonthArray[4] = "/05/";
strMonthArray[5] = "/06/";
strMonthArray[6] = "/07/";
strMonthArray[7] = "/08/";
strMonthArray[8] = "/09/";
strMonthArray[9] = "/10/";
strMonthArray[10] = "/11/";
strMonthArray[11] = "/12/";
strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
}
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
}
}
if (strYear.length == 2) {
strYear = '25' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
}
}
if (isNaN(intMonth)) {
err = 3;
return false;
}
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear-543) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + "" + intday+"" + strYear;
}
else {
datefield.value = intday+""+strMonthArray[intMonth-1]+""+strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear% 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if (intYear % 4 == 0) { return true; }
}
return false;
}
// End -->
</script>
</style>
</HEAD>
<BODY>
<div id="wrapper">
<div id="header">
<img src="images/logo.jpg">
<p align="right">Welcome <?=$objResult["Name"];?> | <a href="index.php">Logout</a></p>
</div>
<div id="topnav">
<ul>
<li><a href="main_page.php">Home</a></li>
</ul>
</div>
<div id="content-wrapper">
<div id="leftnav">
<br>
<ul>
<li><a href="register.php">ลงทะเบียนสมาชิกใหม่</a></li>
<li><a href="user_list.php">แสดงรายชื่อสมาชิก</a></li>
</ul>
</div>
<div id="content">
<table width="800" border="0" align="center">
<tr>
<td colspan="3"><H1 class="style1">::แก้ไขข้อมูลสมัครสมาชิก::</H1>
<FORM action="EditRecordSave.php?EditID=<?=$_GET["EditID"]?>" name="frmEdit">
<?
include "config.inc.php";
$strSQL = "SELECT * FROM member WHERE id = '".$_GET["EditID"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found ID=".$_GET["EditID"];
}
else
{
?>
<TABLE width="514" CELLSPACING="2">
<TR>
<TD><B>ลำดับที่ :</B> </TD>
<TD><input name="id_reg" type="text" size="50" value="<?=$objResult['id']?>"></TD>
</TR>
<TR>
<TD><B>สาขา :</B> </TD>
<TD><input name="branch_reg" type="text" size="50" value="<?=$objResult['branch']?>"> </TD>
</TR>
<TR>
<TD><B>ชื่อ-นามสกุล :</B> </TD>
<TD><input name="name_reg" type="text" size="50" value="<?=$objResult['name']?>"> </TD>
</TR>
<TR>
<TD><B>ชื่อเล่น :</B> </TD>
<TD><INPUT NAME="nick_reg" TYPE="text" value="<?=$objResult['nickname']?>"> </TD>
</TR>
<TR>
<TD><strong>เลขที่บัตรประชาชน:</strong></TD>
<TD>
<input type="text" name="idcard_reg" id="textfield" maxlength="13" value="<?=$objResult['idcard']?>"></TD>
</TR>
<TR>
<TD><B>เพศ :</B> </TD>
<TD><input name="sex_reg" type="text" size="50" value="<?=$objResult['sex']?>"> </TD>
</TR>
<TR>
<TD><strong>วันเดือนปีเกิด:</strong></TD>
<TD>
<input type=text name="birth_reg" onBlur="checkdate(this)" maxlength=11 value="<?=$objResult["birth"];?>" onKeyPress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">
ตัวอย่าง 01/10/52
</TD>
</TR>
<tr>
<TR>
<TD><strong>อายุ:</strong></TD>
<TD>
<input name="age_reg" type="text" id="textfield2" maxlength="2" size="3" value="<?=$objResult["age"];?>">
</TD>
</TR>
<TR>
<TD><B>อีเมล: </B></TD>
<TD><INPUT NAME="email_reg" TYPE="text" SIZE="26" value="<?=$objResult["email"];?>" />
</TD>
</TR>
<TR>
<TD><B>Facebook : </B></TD>
<TD><INPUT NAME="facebook_reg" TYPE="text" value="<?=$objResult["facebook"];?>" > </TD>
</TR>
<TR>
<TD><B>เบอร์โทรศัพท์ : </B></TD>
<TD><INPUT NAME="tel_reg" TYPE="text" SIZE="10" maxlength="10" value="<?=$objResult["telephone"];?>"></TD>
</TR>
<TR>
<TD><B>วันที่สมัคร : </B></TD>
<TD><INPUT NAME="date_reg" TYPE="text" SIZE="10" maxlength="10" value="<?=$objResult["reg_date"];?>"></TD>
</TR>
<TR>
<TD> </TD>
<TD><INPUT TYPE="Submit" name="edit" value="Save">
</TR>
</TABLE>
<?
}
?>
</FORM>
</td>
</tr>
</table>
</div>
</div>
<div id="footer">
@ Siam Professional Admin Services Co., Ltd.
</div>
</div>
</BODY>
</HTML>
File editrecordsave.php
<?
include "config.inc.php";
$strSQL = "UPDATE member SET ";
$strSQL .="id = '".$_POST["id_reg"]."'";
$strSQL .=",branch = '".$_POST["branch_reg"]."'";
$strSQL .=",name = '".$_POST["name_reg"]."'";
$strSQL .=",nickname = '".$_POST["nickname_reg"]."'";
$strSQL .=",idcard = '".$_POST["idcard_reg"]."'";
$strSQL .=",sex = '".$_POST["sex_reg"]."'";
$strSQL .=",birth = '".$_POST["birth_reg"]."'";
$strSQL .=",age = '".$_POST["age_reg"]."'";
$strSQL .=",email = '".$_POST["email_reg"]."'";
$strSQL .=",facebook = '".$_POST["facebook_reg"]."'";
$strSQL .=",telephone = '".$_POST["tel_reg"]."'";
$strSQL .=",reg_date = '".$_POST["date_reg"]."'";
$strSQL .="WHERE id = '".$_GET["EditID"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "<center><font color='#FF0000'>แก้ไขข้อมูลเรียบร้อยแล้ว</b></font></center>";
echo'<meta http-equiv="refresh" content="2; URL=register.php">';
echo $objQuery;
exit();
}
else
{
echo "Error Save [".$strSQL."]";
}
?>
ผมลอง echo $objQuery; แล้วคำตอบได้ 1 ครับ ช่วยดูให้หน่อยว่าผิดพลาดตรงไหน
ขอบคุณทุกความเห็นครับ
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-08-02 21:06:13 |
By :
sandeekrub |
View :
901 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$objQuery = mysql_query($strSQL);
echo $strSQL;
เอา SQL ออกมาดูครับ
|
|
|
|
|
Date :
2011-08-02 21:24:59 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง echo $strSQL แล้วครับ
ผลลัพธ์ที่ออกมาคือ เลข 1 ครับผม
|
|
|
|
|
Date :
2011-08-03 10:18:01 |
By :
sandeekrub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ เขียนใหม่หมดเลย เลยไม่รู้ว่าผิดตรงไหน ขอบคุณ K.mr.win ครับสำหรับคำแนะนำ
|
|
|
|
|
Date :
2011-08-03 17:31:14 |
By :
sandeekrub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|