|
 |
|
ขอวิธีการเขียนโค้ดให้ติดต่อกับฐานข้อมูลmsql เมื่อมีคนมาสมัครสมาชิกให้ข้อมูลนั้นไปอยู่ในตาราง |
|
 |
|
|
 |
 |
|
ให้มันอยู่ในตารางของฐานข้อมูลนะครับ ขอโค้ดตัวอย่างเลยได้ไหมครับผมพึ่งจะเรียนอ่ะครับแล้วไม่ค่อยเข้าใจเท่าไรอ่ะครับ
|
 |
 |
 |
 |
Date :
2011-10-08 12:14:51 |
By :
playboyzar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาตัวอย่างไปดูเลยละกัน
registrationform.php
Code (PHP)
<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{
// ** START **
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
if (form.username.value == "") {
alert( "กรุณากรอกชื่อเข้าระบบ" );
form.username.focus();
return false ;
}
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)==false){
alert("อีเมลมีรูปแบบไม่ถูกต้อง!")
form.email.focus();
return false;
}
if (form.password.value == "") {
alert( "กรุณากรอกรหัสผ่าน" );
form.password.focus();
return false ;
}
if (form.password.value != form.repassword.value) {
alert( "กรุณากรอกรหัสผ่านยืนยันให้ตรงกัน" );
form.repassword.focus();
return false ;
}
// ** END **
return true ;
}
//-->
</script>
<form action=registrationadd.php method=post onSubmit="return checkform(this);">
<table width=800 border=0 cellpadding=2 cellspacing=0>
<tr>
<th colspan=2><strong>«« ลงทะเบียนสำหรับเข้าใช้งานระบบ »»</strong>
</th>
</tr>
<tr>
<td width=50% align=right>ชื่อเข้าระบบ
</td>
<td width=50% align=left><input type="text" name="username" id="username" size="20" > *
</td>
</tr>
<tr>
<td align=right>อีเมล
</td>
<td align=left><input type=text name=email size=20 /> *
</td>
</tr>
<tr>
<td align=right>รหัสผ่าน
</td>
<td align=left><input type=password name=password size=20 maxlength=20 /> *
</td>
</tr>
<tr>
<td align=right>ยืนยันรหัสผ่านให้เหมือนกัน
</td>
<td align=left><input type=password name=repassword size=20 maxlength=20 /> *
</td>
</tr>
<tr>
<td colspan=2>
<input type=submit name="submit" value="ลงทะเบียน" >
</td>
</tr>
</table>
</form>
registrationadd.php
Code (PHP)
<?php
$host="localhost";
$user="youruser";
$password="yourpassword";
$db="yourdb";
$conn=mysql_connect ($host,$user,$password) or die("Cannot connect to database");
$dbselect=mysql_select_db($db,$conn);
$username=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['password'];
$md5password=md5($password);
$date_regist=date('Y-m-y H:i:s',time());
echo "username : $username";
echo "<br>password : $password";
$sql="INSERT INTO ba_user (username,email,password,date_regist) VALUES ('$username','$email','$md5password','$date_regist')";
$result=mysql_query($sql,$conn);
if ($result) {echo "<br>ลงทะเบียนเรียบร้อย";}
?>
|
ประวัติการแก้ไข 2011-10-08 18:48:17
 |
 |
 |
 |
Date :
2011-10-08 18:47:51 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|