|
 |
|
อาจาร์ยใน thaicreate ทั้งหลายช่วยชี้ทางแสงสว่างให้ผมที่ ครับ ผมเปลียนชื่อ ดาต้าเบสแล้วไม่ผ่านน่ะครับ |
|
 |
|
|
 |
 |
|
คือว่าผมได้ลองทำการเปลียนชื่อ ดาต้าเบส และ ตารางที่สร้างตามหนังสือ จากที่นี้ C:\AppServ\MySQL\data โดยตรง แล้วไปดูใน ฐานข้อมูลมันก็เปลี่ยนได้จริงๆ แต่ก็มีปัญหาตามมาน่ะครับ คือว่า ในระบบสมาชิกผมสมัคร ไปแล้วมันขึ้นข้อความว่า
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\member\register2.php on line 20
ไม่สามารถสมัครเป็นสมาชิกได้
อันนี้โค๊ด ก่อนทำการเปลี่ยนแปลง
Code (PHP)
<?
$user_reg=$_POST[user_reg];
$pass_reg=$_POST[pass_reg];
$name_reg=$_POST[name_reg];
$sex_reg=$_POST[sex_reg];
$email_reg=$_POST[email_reg];
$address_reg=$_POST[address_reg];
$date_reg=date("Y-m-d");
if ($user_reg=="" or $pass_reg=="" or $name_reg=="" ) {
echo "<h3>ERROR : กรุณากรอกข้อมูลให้ครบนะครับ<h3>"; exit();
}
include "function.php";
if (!checkemail($email_reg)) {
echo "<h3>ERROR : รูปแบบอีเมลที่กรอกไม่ถูกต้องนะครับ </h3>"; exit();
}
include "connect.php";
$sql="select * from tb_member where username='$user_reg' ";
$result=mysql_db_query($dbname,$sql);
$num=mysql_num_rows($result);
if($num>0) {
echo "<h3>ERROR : Username ซ้ำครับ </h3>"; exit();
}
$sql="insert into tb_member values('','$user_reg','$pass_reg','$name_reg','$sex_reg',
'$email_reg','$tel_reg','$address_reg','$date_reg')";
$result=mysql_db_query($dbname,$sql);
if ($result) {
echo "<h3>ข้อมูลของท่านถูกบันทึกเรียบร้อยแล้ว</h3>";
echo "<A HREF='index.html'>คลิกเพื่อเข้าระบบสมาชิก</A><BR><BR>";
} else {
echo "<h3>ไม่สามารถสมัครเป็นสมาชิกได้</h3>";
}
mysql_close();
?>
อันนี้โค๊ด หลังทำการเปลี่ยนแปลง
Code (PHP)
<?
$user_reg=$_POST[user_reg];
$pass_reg=$_POST[pass_reg];
$name_reg=$_POST[name_reg];
$sex_reg=$_POST[sex_reg];
$email_reg=$_POST[email_reg];
$address_reg=$_POST[address_reg];
$date_reg=date("Y-m-d");
if ($user_reg=="" or $pass_reg=="" or $name_reg=="" ) {
echo "<h3>ERROR : กรุณากรอกข้อมูลให้ครบนะครับ<h3>"; exit();
}
include "function.php";
if (!checkemail($email_reg)) {
echo "<h3>ERROR : รูปแบบอีเมลที่กรอกไม่ถูกต้องนะครับ </h3>"; exit();
}
include "connect.php";
$sql="select * from member where mem_username='$user_reg' ";
$result=mysql_db_query($dbname,$sql);
$num=mysql_num_rows($result);
if($num>0) {
echo "<h3>ERROR : Username ซ้ำครับ </h3>"; exit();
}
$sql="insert into member values('','$user_reg','$pass_reg','$name_reg','$sex_reg',
'$email_reg','$tel_reg','$address_reg','$date_reg')";
$result=mysql_db_query($dbname,$sql);
if ($result) {
echo "<h3>ข้อมูลของท่านถูกบันทึกเรียบร้อยแล้ว</h3>";
echo "<A HREF='index.html'>คลิกเพื่อเข้าระบบสมาชิก</A><BR><BR>";
} else {
echo "<h3>ไม่สามารถสมัครเป็นสมาชิกได้</h3>";
}
mysql_close();
?>
ภาพอันนี้ ฐานข้อมูลผมครับ

Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2010-08-27 12:44:01 |
By :
sodakiller |
View :
1018 |
Reply :
10 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา code ของไฟล์ connect.php มาดูหน่อยครับ
|
 |
 |
 |
 |
Date :
2010-08-27 13:15:36 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$dbname="db_member";
เปลี่ยนเป็น
$dbname="member";
|
 |
 |
 |
 |
Date :
2010-08-27 16:55:53 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้กำลังคิดว่าจะลอง เปลี่ยน ชื่อตาราง กับ ดาต้า ที่ละขั้นจะลองใหม่หมดเลย
ผมมาลองสังเกตดูตรง tel_reg' ใน รีจีเตอร์2 มันไม่มีแหะ แต่ ตอนทำของโค๊ดต้นฉบับ มันก็เป็นยังงี้แหละแต่กลับรันผ่านมันแปลกๆแหะ
|
ประวัติการแก้ไข 2010-08-28 17:40:39
 |
 |
 |
 |
Date :
2010-08-28 17:37:17 |
By :
sodakiller |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
$host="localhost";
$user="root";
$pw="1234";
$dbname="db_member";
$c = mysql_connect($host,$user,$pw);
if (!$c) {
echo "<h3>ERROR : ไม่สามารถติดต่อฐานข้อมูลได้</h3>";
exit();
}
?>
เห็นบอกว่า ฐานข้อมูลผมใช้เป็น Mydatabase ตารางใช้เป็น member ครับ แต่ทำไม $dbname เป็น db_member ล่ะ ทำไมไม่เป็น Mydatabase ลองเปลี่ยนดูนะจ๊ะ
|
 |
 |
 |
 |
Date :
2010-08-28 18:08:27 |
By :
zankumuro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|