Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > การดึงข้อมูลและการตรวจสอบข้อมูล ก่อนลงฐานข้อมูลครับ รบกวนหน่อยนะครับ



 

การดึงข้อมูลและการตรวจสอบข้อมูล ก่อนลงฐานข้อมูลครับ รบกวนหน่อยนะครับ

 



Topic : 094154



โพสกระทู้ ( 12 )
บทความ ( 0 )



สถานะออฟไลน์




ผมดึงข้อมูลที่กรอกในหน้า register มาตรวจสอบ username ซ้ำครับ



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-04-23 23:56:01 By : moterzisesix View : 967 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

PHP MySQL Check Already Exists Add/Insert Record







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-04-24 06:31:06 By : mr.win
 


 

No. 2



โพสกระทู้ ( 12 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณสำหรับคำตอบครับ ในส่วนนี้ผมทำผ่านแล้วครับ ปัญหาที่ติดคือ ผมดึงค่าที่กรอกใน form จากอีกหน้ามา มา action มายังหน้า check ผมจะให้แก้ username ที่ซ้ำผ่านนหน้านี้เลยอ่ะครับ ผลที่ได้ก็คือ ถ้ากรอก username ไม่ซ้ำ มันจะลงฐานข้อมูลปกติ แต่ถ้า username ซ้ำเวลาแก้แล้ว มันกลับลงฐานข้อมูลแค่ username ที่แก้อ่ะครับ ค่าอื่นๆ หายเกลี้ยง

อันนี้เป็น code ของหน้า check อ่ะครับ

Code (PHP)
<?php
include("config.inc.php") ;
session_start() ;
$username_customer=$_POST['username_customer'];
$password_customer=$_POST['password_customer'];
$name_customer=$_POST['fname_customer'];
$lastname_customer=$_POST['lname_customer'];
$date_customer=$_POST['date_customer'];
$month_customer=$_POST['month_customer'];
$year_customer=$_POST['year_customer'];
$age_customer=$_POST['age_customer'];
$sex_customer=$_POST['sex_customer'];
$solder_customer=$_POST['solder_customer'];
$address_customer=$_POST['address_customer'];
$location_customer=$_POST['location_customer'];
$geo_customer=$_POST['geo_customer'];
$province_customer=$_POST['province_customer'];
$subject_customer=$_POST['subject_customer'];
$district_customer=$_POST['district_customer'];
$zipcode_customer=$_POST['zipcode_customer'];
$nationnal_customer=$_POST['nationnal_customer'];
$namenationnal_customer=$_POST['namenationnal_customer'];
$city_customer=$_POST['city_customer'];
$email_customer=$_POST['email_customer'];
$telephone_customer=$_POST['telephone_customer'];
$mobile_customer=$_POST['mobile_customer'];
?>
<!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>Me Jobs | ผลการลงทะเบียน</title>
</head>

<body>
<?php
$signup_customer = date("j/n/").(date("Y")+543) ;
// ตรวจสอบว่ามีชื่อ user นี้ใช้ไปหรือยัง
$sql = "select username_customer from member_customer where username_customer='$username_customer'" ;
$result = mysql_query($sql) ;
$numrow = mysql_num_rows($result) ;
if($numrow!=0) {
	?>
<table width='500' height='150' border='0' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td><center><img src='image/logo.png'></center></td>
  </tr>
</table>
<table width='500' height='180' background='image/bgerror.png' border='0' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td><font face='Tahoma' color='#FF0000' size='3'>&nbsp;&nbsp;&nbsp;&nbsp;ERROR!...</font> <br><font face='Tahoma' color='#FF6600' size='2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Username <font color="#0000FF"><?php echo "$username_customer"; ?></font> มีผู้ใช้งานแล้ว กรุณาเปลี่ยน Username ใหม่<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ด้วยครับ</font></td>
  </tr>
  <tr>
    <td><center><a href='#login-box' class='login-window'>EDIT USERNAME CLICK!</a></center></td>
  </tr>
</table>
<div id="login-box" class="login-popup">
<a href="#" class="close"><img src="image/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>
<form method="post" class="signin" action="customer_add.php" id="checkusername" name="checkusername" OnSubmit="return checkvalue();">
	<fieldset class="textbox">
		<label class="username">
			<span>Username</span>
			<input id="username_customer" name="username_customer" value="" type="text" autocomplete="on" placeholder="<?php echo "$username_customer"; ?>">
		</label>
		<button id="Submit" name="Submit" class="submit button" type="Submit">ยืนยัน</button>
	</fieldset>
</form>
</div>
<?
exit ();
}
?>
<?
// ถ้ายังไม่มีผู้ใช้ชื่อ user นี้

$sql = "select * from member_customer order by id_customer desc" ;
$result = mysql_query($sql) ;
$num_result  = mysql_num_rows($result) ;
$dbarr = mysql_fetch_row($result) ;
$member_db = $dbarr[0]+1 ; // นำค่า id มาเพิ่มให้กับค่ารหัสสมาชิกครั้งละ1
if($member_db>=100) {
$member_in = "CUS0$member_db" ;
}
else {
if($member_db >=10) {
$member_in = "CUS00$member_db" ;
}
else {
$member_in = "CUS000$member_db" ;
}
}

$no_customer = $yourcode.$member_in; // รหัสสมาชิกเช่น ip0001
$result = "insert into member_customer (no_customer,username_customer,password_customer, name_customer,lastname_customer,date_customer,month_customer, year_customer,age_customer,sex_customer,solder_customer,address_customer, location_customer,geo_customer,province_customer,subject_customer,district_customer, zipcode_customer,nationnal_customer,name_nationnal_customer,city_customer,email_customer ,telephone_customer,mobile_customer,signup_customer)
                                                  values('$no_customer','$username_customer', '$password_customer','$name_customer' ,'$lastname_customer','$date_customer','$month_customer','$year_customer','$age_customer', '$sex_customer','$solder_customer','$address_customer','$location_customer','$geo_customer', '$province_customer','$subject_customer','$district_customer','$zipcode_customer','$nationnal_customer', '$namenationnal_customer','$city_customer','$email_customer','$telephone_customer','$mobile_customer' ,'$signup_customer')";
												  
if(mysql_query ($result)){
	echo " บันทึกข้อมูลเรียบร้อยแล้ว";
	}else{
		echo mysql_error();
		}
		?>    
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-04-24 17:36:21 By : moterzisesix
 

 

No. 3



โพสกระทู้ ( 52 )
บทความ ( 0 )



สถานะออฟไลน์


Code (PHP)
<?php
session_start() ;
$objConnect = mysql_connect("localhost","root","root");
$objDB = mysql_select_db("3_db_computer");

$username_customer=$_REQUEST['username_customer'];
$password_customer=$_POST['password_customer'];
$name_customer=$_POST['fname_customer'];
$email_customer=$_POST['email_customer'];
$telephone_customer=$_POST['telephone_customer'];

//$username_customer="pissanu101";
//$password_customer="062293046";
//$name_customer="pissanu";
//$email_customer="[email protected]";
//$telephone_customer="0801948484";

?>
<!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=TIS-620" />
<title>Me Jobs | ผลการลงทะเบียน</title>
</head>

<body>
<?php
//$signup_customer = date("j/n/").(date("Y")+543) ;
// ตรวจสอบว่ามีชื่อ user นี้ใช้ไปหรือยัง
$result = mysql_query("select * from member where Username='$username_customer'") ;

$numrow = mysql_num_rows($result) ;
if($numrow!=0) {
	?>
<table width='500' height='150' border='0' cellspacing='0'
	cellpadding='0' align='center'>
	<tr>
		<td>
		<center><img src='image/logo.png'></center>
		</td>
	</tr>
</table>
<table width='500' height='180' background='image/bgerror.png'
	border='0' cellspacing='0' cellpadding='0' align='center'>
	<tr>
		<td><font face='Tahoma' color='#FF0000' size='3'>&nbsp;&nbsp;&nbsp;&nbsp;ERROR!...</font>
		<br>
		<font face='Tahoma' color='#FF6600' size='2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Username
		<font color="#0000FF"><?php echo "$username_customer"; ?></font>
		มีผู้ใช้งานแล้ว กรุณาเปลี่ยน Username ใหม่<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ด้วยครับ</font></td>
	</tr>
	<tr>
		<td>
		<center><a href='#login-box' class='login-window'>EDIT USERNAME CLICK!</a></center>
		</td>
	</tr>
</table>
<div id="login-box" class="login-popup"><a href="#" class="close"><img
	src="image/close_pop.png" class="btn_close" title="Close Window"
	alt="Close" /></a>
<form method="post" class="signin" action="customer_add.php"
	id="checkusername" name="checkusername" OnSubmit="return checkvalue();">
<fieldset class="textbox"><label class="username"> <span>Username</span>
<input id="username_customer" name="username_customer" value=""
	type="text" autocomplete="on"
	placeholder="<?php echo "$username_customer"; ?>"> </label>
<button id="Submit" name="Submit" class="submit button" type="submit">ยืนยัน</button>
</fieldset>
</form>
</div>
	<?
	exit ();
}
// ถ้ายังไม่มีผู้ใช้ชื่อ user นี้

//$no_customer = $yourcode.$member_in; // รหัสสมาชิกเช่น ip0001
$result = mysql_query("insert into member set Username='$username_customer',
	Password='$password_customer',
	Name='$name_customer',
	Tel='$telephone_customer',
	Email='$email_customer'");

if($result){
	echo " บันทึกข้อมูลเรียบร้อยแล้ว";
}else{
	echo mysql_error();
}

?>
</body>
</html>



เช็คดูแล้ว ก็ได้นะคับ แต่รองเปลี่ยนค่าที่ กรอก รายละเอียดต่างๆๆ ลองดูนะคับ เพื่อ มันจำค่าเก่า ทำให้ เช็คค่า ซ้ำ นะ คับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-04-26 10:14:22 By : pissanu101
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : การดึงข้อมูลและการตรวจสอบข้อมูล ก่อนลงฐานข้อมูลครับ รบกวนหน่อยนะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่