|
 |
|
เพิ่มข้อมูลลงฐานข้อมูลไม่ได้ครับ รบกวนดูโค้ดให้หน่อยครับ เพราะหนังสือที่ผมซื้อมาผิดเยอะมาก copyตัวอย่างมารันครับ ยังไม่ได้ |
|
 |
|
|
 |
 |
|
1.ไฟล์ addmember.php ที่อยู่ C:\AppServ\www\Projcet\workshop_11
Code (PHP)
<?php
session_start();
include "include/config.php";
$strName = $_POST["tName"];
$strEmail= $_POST['tEmail'];
$strLogin = $_POST['tLogin'];
$strPwd = $_POST['tPwd'];
$strCaptcha=$_POST['tCaptcha'];
$strMode = $_POST["action"];
if ($strMode=="ADD") {
if($_SESSION["security_code"]==$strCaptcha){
$sql = "INSERT INTO tbl_member VALUES (0, '$strName', '$strEmail', '$strLogin', '$strPwd', '','')";
$result = @mysql_query($sql) or die(mysql_error());
if($result) {
echo "<font color=#009900>บันทึกข้อมูลเรียบร้อยแล้ว</font><br><a href=\"javascript:window.close();\">หน้าต่างนี้</a>";
} else {
echo "<font color=#FF0000>ไม่สามารถบันทึกข้อมูลได้</font>";
}
} else {
echo "<font color=#FF0000>คุณไม่ผ่านการตรวจสอบ <br>กรุณาลองใหม่อีกครั้งครับ</font>";
}
}
if ($strMode=="EDIT") {
if($_SESSION["security_code"]==$strCaptcha){
$sql = "UPDATE tbl_member SET member_name='$strName', member_email='$strEmail', member_pwd='$strPwd' WHERE member_login='$strLogin'";
$result = @mysql_query($sql) or die(mysql_error());
if($result) {
echo "<font color=#009900>แก้ไขข้อมูลเรียบร้อยแล้ว</font><br><a href=\"javascript:window.close();\">หน้าต่างนี้</a>";
} else {
echo "<font color=#FF0000>ไม่สามารถแก้ไขข้อมูลได้</font>";
}
} else {
echo "<font color=#FF0000>คุณไม่ผ่านการตรวจสอบ <br>กรุณาลองใหม่อีกครั้ง</font>";
}
}
mysql_close();
?>
2.frmRegister.html ที่อยุ่ C:\AppServ\www\Projcet\workshop_11
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Member</title>
<link rel="stylesheet" href="include/style.css" type="text/css" />
</head>
<script type="text/javascript" src="ajax/ajaxmember.js"></script>
<body>
<form name="form1" id="form1">
<table cellspacing=5 cellpadding=0 width=450 align=center>
<tr>
<td align="center" colspan="2"><h1>สมัครสมาชิก</h1></td>
</tr>
<tr>
<td align="right">ชื่อ:</td>
<td><input name="txtname" type="text" id="txtname" size="25" /></td>
</tr>
<tr>
<td align="right">Email:</td>
<td><input name="txtemail" type="text" id="txtemail" size="25" /></td>
</tr>
<tr>
<td align="right">Login:</td>
<td><input name="txtlogin" type="text" id="txtlogin" size="25" /></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input name="password" type="password" id="password" size="25" /></td>
</tr>
<tr>
<td align="right" valign="top">Confirm Password:</td>
<td><input name="repassword" type="password" id="repassword" size="25" onKeyUp="checkpass(form1.password.value, form1.repassword.value)"/><br><div id="msg"></div></td>
</tr>
<tr>
<td align="right" valign="top">พิมพ์อักขระสีแดงในภาพ:</td>
<td><img id="imgCaptcha" src="redcaptcha.php" /><br><input type="text" id="txtCaptcha" name="txtCaptcha" size="3" maxlength="6" disabled> <img src="image/icon_refresh.jpg" width="17" height="18" border="0" onClick="javascript:refreshCap()"><br><div id="msg3"></div></td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="btnSubmit" id="btnSubmit" value="สมัครสมาชิก" disabled OnClick="check_data(form1.txtname.value, form1.txtemail.value, form1.txtlogin.value, form1.password.value, form1.txtCaptcha.value, 'ADD')"><br><br><div id="result"></div></td>
</tr>
</table>
</form>
</body>
</html>
3.ไฟล์ config.php ที่อยุ่ C:\AppServ\www\Projcet\workshop_11\include
Code (PHP)
<?php
$objConnect = mysql_connect("localhost","root","1234") or die(mysql_error());
$objDB = mysql_select_db("ajaxmember");
mysql_query("SET NAMES utf8", $objConnect);
?>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, CakePHP

|
|
 |
 |
 |
 |
Date :
2012-01-08 19:59:32 |
By :
เบียร์ |
View :
1086 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$result = mysql_query($sql) or die(mysql_error());
เอา @ ออกครับ 
|
 |
 |
 |
 |
Date :
2012-01-08 22:07:23 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|