สอบถามปัญหาการเขียนโค้ดของระบบ Register / PHP / E-mail
พอดีเขาเขียนเว็บขึ้นมาค่ะ แล้วก็มาเปิดดูโค้ดเอา เป็นมือใหม่หัดเขียน
แล้วเราก็เอาโค้ดที่ได้มาเพิ่มเนื้อหานิดหน่อย
มันก็ทำงานได้ดี ไม่มีแจ้งเตือนอะไรค่ะ แต่พอเข้าไปดูในดาต้าเบส ปรากฎดว่าข้อมูลที่กรอกไป ไม่เข้า
แก้อยู่นานเลยค่ะ ไม่เข้าใจจริง ๆ ใครพอแก้ได้ช่วบอกหน่อยนะค่ะ
Register.php
Code (PHP)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>tast</title>
</head>
<body>
<p> </p>
<form name="form1" method="post" action="../3.php">
<table width="646" border="0" align="center">
<tr>
<th width="242" align="left"> Username</th>
<th width="394" align="left"><label for="txtuname"></label>
<input name="txtuname" type="text" id="txtuname" size="40"></th>
</tr>
<tr>
<th align="left"> Password</th>
<th align="left"><input name="txtpass" type="password" id="txtpass" size="40"></th>
</tr>
<tr>
<th align="left"> Confirm Password</th>
<th align="left"><label for="txtconfirmpass"></label>
<input name="txtconfirmpass" type="password" id="txtconfirmpass" size="40"></th>
</tr>
<tr>
<th align="left">ชื่อ</th>
<th align="left"><label for="txtname"></label>
<input name="txtname" type="text" id="txtname" tabindex="40" size="40"></th>
</tr>
<tr>
<th align="left">นามสกุล</th>
<th align="left"><label for="txtlast"></label>
<input name="txtlast" type="text" id="txtlast" size="40"></th>
</tr>
<tr>
<th align="left" valign="top">รหัสบัตรประชาชน</th>
<th align="left"><label for="txtidcard"></label>
<input name="txtidcard" type="text" id="txtidcard" size="40" maxlength="13"></th>
</tr>
<tr>
<th align="left" valign="top">ที่อยู่</th>
<th align="left"><label for="txtaddress"></label>
<textarea name="txtaddress" cols="40" id="txtaddress"></textarea></th>
</tr>
<tr>
<th align="left">เบอร์โทรศัพท์</th>
<th align="left"><label for="txtcall"></label>
<input name="txtcall" type="text" id="txtcall" size="40"></th>
</tr>
<tr>
<th align="left">E-mail</th>
<th align="left"><label for="txtemail"></label>
<input name="txtemail" type="text" id="txtemail" size="40"></th>
</tr>
<tr>
<th align="left">จบรุ่นที่</th>
<th align="left"><label for="txtyear"></label>
<input name="txtyear" type="text" id="txtyear" size="15" maxlength="4"></th>
</tr>
<tr>
<th colspan="2" align="center"><input type="submit" name="save" id="save" value="สมัครสมาชิก">
<input type="reset" name="Reset" id="button" value="ล้างข้อมูล"></th>
</tr>
</table>
</form>
</body>
</html>
ส่วนไฟล์ที่ทำการส่งอยู่อีกโฟเดอร์ ชื่อไฟล์ 3.php
Code (PHP)
<?php
session_start();
mysql_connect("localhost","root","root");
mysql_select_db("863811");
if(trim($_POST["txtuname"]) == "")
{
echo "<script>alert('กรุณากรอกชื่อผู้ใช้ของท่าน!');</script>";
exit();
}
if(trim($_POST["txtpass"]) == "")
{
echo "<script>alert('กรุณากรอกรหัสผ่าน!');</script>";
exit();
}
if($_POST["txtpass"] != $_POST["txtconfirmpass"])
{
echo "<script>alert('รหัสผ่านไม้ตรงกัน กรุณากรอกใหม่!');</script>";
exit();
}
if(trim($_POST["txtname"]) == "")
{
echo "<script>alert('กรุุณากรอกชื่อของท่าน');</script>";
exit();
}
if(trim($_POST["txtlast"]) == "")
{
echo "<script>alert('กรุุณากรอกนามสกุลของท่าน');</script>";
exit();
}
if(trim($_POST["txtidcard"]) == "")
{
echo "<script>alert('กรุุณากรอกเลขบัตรประจำตัวประชาชนของท่าน');</script>";
exit();
}
if(trim($_POST["txtaddress"]) == "")
{
echo "<script>alert('กรุุณากรอกที่อยู่ของท่าน!';</script>";
exit();
}
if(trim($_POST["txtcall"]) == "")
{
echo "<script>alert('กรุุณากรอกเบอร์โทรศัพท์ของท่าน');</script>";
exit();
}
if(trim($_POST["txtemail"]) == "")
{
echo "<script>alert('กรุุณากรอก E-mail ของท่าน');</script>";
exit();
}
if(trim($_POST["txtyear"]) == "")
{
echo "<script>alert('กรุุณากรอกรุ่นที่จบของท่าน');</script>";
exit();
}
$strSQL = "SELECT * FROM mem WHERE Username = '".trim($_POST['txtuname'])."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<script>alert('มีชื่อผู้ใช้นี้แล้ว กรุณากรอกซื่อผู้ใช้ใหม่');</script>";
}
else
{
mysql_connect("localhost","root","root");
mysql_select_db("863811");
$strSQL = "INSERT INTO mem (Username,Password,Name,LastName,IDCard,Address,Call,Email,Year,Status,Active) VALUES ('".$_POST["txtuname"]."',
'".$_POST["txtpass"]."','".$_POST["txtname"]."' ,'".$_POST["txtlast"]."' ,'".$_POST["txtidcard"]."' ,'".$_POST["txtaddress"]."' ,'".$_POST["txtcall"]."' ,'".$_POST["txtemail"]."','".$_POST["txtyear"]."','USER','".session_id()."','No')";
$objQuery = mysql_query($strSQL);
$Uid = mysql_insert_id();
echo "<script>alert('ทำการสมัครสมาชิดเรียบร้อบแล้ว!<br>กรุณาตรวจสอบ E-mail เเพื่อทำการยืนยันการสมัครสมาชิก');;window.location='index.php';</script>";
$strTo = $_POST["txtemail"];
$strSubject = "ขั้นตอนการยืนยันการสมัครสมาชิกสมาคมศิษย์เก่าบวรนิเวศ";
$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "From: [email protected] \nReply-To: [email protected] ";
$strMessage = "";
$strMessage .= "ยินดีต้อนรับ : ".$_POST["txtname"]."<br>";
$strMessage .= "=================================<br>";
$strMessage .= "วิธีการยืนยันการสมัครสมาชิก<br>";
$strMessage .= "=================================<br>";
$strMessage .= "ขอบคุณ<br>";
$flgSend = mail($strTo,$strSubject,$strMessage,$strHeader);
}
mysql_close();
?>
ขอความกรุณาด้วยน่ะTag : PHP, MySQL
ประวัติการแก้ไข 2015-08-12 10:24:53
Date :
2015-08-12 10:22:31
By :
Narybee
View :
1035
Reply :
5
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Call,Email,Year,Status,Active) VALUES ('rosir', '123','Rosirro' ,'Rosetta' ,'' at line 1 ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2015-08-12 12:46:24
รายละเอียดของการตอบ ::
ค่ะลองทำตามที่บอกปรากฎว่ามันขึ้น
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Call,Email,Year,Status,Active) VALUES ('rosir', '123','Rosirro' ,'Rosetta' ,'' at line 1
Date :
2015-08-12 18:55:14
By :
Narybee
ทำได้ แล้วววววว
ขอบคุณมากค่ะ
เป็นเพราะคำสงวน ค่ะ
ขอบคุณทุกคนมากเลยค่ะ
Date :
2015-08-13 00:30:12
By :
Narybee
Date :
2015-08-13 09:10:28
By :
mr.win
Load balance : Server 03