|
 |
|
ช่วยแก้โคตหน่อย เชื่อมต่อต่อฐานข้อมูลไม่ได้ |
|
 |
|
|
 |
 |
|
member.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>สมัครสมาชิก</title>
<style type="text/css">
.fls{width:70%;
height:40%;
}
.x-button{
border-style:solid;
border-width:1;
border-color:#090;
color:#090;
width:100px;
font-size:14px;
font-family:Tahoma, Geneva, sans-serif;
font-weight:bold;
}
</style>
</head>
<body >
<form method="POST" action="savemember.php">
<table >
<tr>
<td><label>ชื่อ</label></td>
<td><label>:</label></td>
<td><input type="text" name="fname" id="fname" /></td>
</tr>
<tr>
<td><label>นามสกุล</label></td>
<td><label>:</label></td>
<td><input type="text" name="lname" id="lname" /></td>
</tr>
<tr>
<td><label>ที่อยู่</label></td>
<td><label>:</label></td>
<td><label>
<textarea name="address" id="textarea" cols="30" rows="5"></textarea>
</label></td>
</tr>
<td><label>เบอร์โทรศัพท์</label></td>
<td><label>:</label></td>
<td><input type="text" name="tel" maxlength="10" /></td>
</tr>
<tr>
<td><label>อีเมล</label></td>
<td><label>:</label></td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<tr>
<td><label>จํานวนที่ต้องการซัก</label></td>
<td><label>:</label></td>
<td><input type="text" name="total" maxlength="4" size="4"/> ชิ้น/เดือน</td>
</tr>
<tr>
<td><label>อีเมลเพื่อเข้าสู่ระบบ </label></td>
<td><label>:</label></td>
<td><input type="text" name="email_login" id="email_login" /></td>
</tr>
<tr>
<td><label>รหัสผ่านเพื่อเข้าสู่ระบบ</label></td>
<td><label>:</label></td>
<td><input type="password" name="pass_login" id="pass_loin" /></td>
</tr>
<tr>
<td><label>ยืนยันรหัสผ่าน</label></td>
<td><label>:</label></td>
<td><input type="password" name="pass_login2" id="pass_login2" /></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" value="ลงทะเบียน" class="x-button"/>
<input type="reset" value="ยกเลิก" class="x-button"/></td>
</tr>
</table>
</form>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------------------------
savemember.php
<?php
include_once("connection.php");
if(connection_db()){
$str = "INSERT INTO customer(first_name,last_name,address,tel,email,total,email_user,email_user1,pass) ";
$str .= "VALUES(".$_POST['fname'].",'".$_POST['lname']."','".$_POST['address']."','".$_POST['tel']."','".$_POST['email']."','".$_POST['total']."','".$_POST['email_login']."','".$_POST['pass_login']."','".$_POST['pass_login2']."')";
if(mysql_query($str)){
echo "<p>บันทึกข้อมูลเสร็จเรียบร้อย</p>";
}else{
echo "<p>ไม่สามารถบันทึกข้อมูลได้กรุณาลองใหม่อีกครั้ง</p>";
}
disconnect_db();
}
else{
echo "<p>ไม่สามารถเชื่อมต่อฐานข้อมูลได้</p>";
}
?>
------------------------------------------------------------------------------------------
connection.php
<?
$conn = "";
function connection_db(){
$encode[0] = "SET character_set_results=utf8";
$encode[1] = "SET character_set_client=utf8";
$encode[2] = "SET character_set_connection=utf8";
$conn = mysql_connect("localhost","root","adl");
if($conn){
if(mysql_select_db("laundry")){
$i = 0;
while($i<3){
mysql_query($encode[$i]);
$i++;
}
return true;
}else{
return false;
}
}else{
return false;
}
}
function disconnect_db(){
mysql_close();
}
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2010-08-20 16:29:35 |
By :
banana |
View :
790 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$conn รับค่าชื่อฐานข้อมูลมายังไงละครับ
|
 |
 |
 |
 |
Date :
2010-08-20 16:36:51 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลบ $conn ไปเลยครับ
$conn = ""; ผมเห็นว่ามันไม่สำคัญไรเลยครับ และอีกอย่างคุณก็ได้ประกาศเรียกใช้การ connect แล้ว ถ้าคุณไม่ลบออก มันจะมองว่า ว่าไรดีหวา อิอิอิ เก็บไปคิดเป้นการบ้านนะครับ แต่แนะนำลบออกเลยครับ $conn ตัวแรก เลยอะ
|
 |
 |
 |
 |
Date :
2010-08-20 16:59:14 |
By :
SOUL |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|