ช่วยดูโค้ดให้หน่อยนะค่ะ วันขึ้นแบบนี้ยังไง หาไม่เจออ่ะค่ะ ไม่รู้จะแก้ยังไงพอดีพึ่งเริ่มศึกษาอ่ะค่ะ
Code (PHP)
<h1>ระบบสมาชิก</h1>
<div>[ <a href="index.php?f=adduser&action=add">เพิ่มสมาชิก</a> ]</div>
<table width="95%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><div align="right">
<form name="form1" method="post" action="index.php?f=adduser">
<input name="s" type="text" id="s" value="<?php echo $_POST[s];?>">
<select name="t" id="t">
<option value="">ค้นหาจาก</option>
<option value="IDCard" <?php if($_POST[t] == "IDCard"){?> selected="selected"<?php } ?>>รหัสประจำตัวประชาชน</option>
<option value="Name"<?php if($_POST[t] == "Name"){?> selected="selected"<?php } ?>>ชื่อ</option>
<option value="Lastname"<?php if($_POST[t] == "Lastname"){?> selected="selected"<?php } ?>>นามสกุล</option>
<option value="Address" <?php if($_POST[t] == "Address"){?> selected="selected"<?php } ?>>ที่อยู่</option>
<option value="Username" <?php if($_POST[t] == "Username"){?> selected="selected"<?php } ?>>Username</option>
<option value="Phone" <?php if($_POST[t] == "Phone"){?> selected="selected"<?php } ?>>เบอร์โทรศัพท์</option>
</select>
<input type="submit" name="Submit" value="ค้นหา">
</form>
</div></td>
</tr>
<tr>
<td><div align="center">
<table width="75%" style="margin-top:50px;" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="63%"><div align="center">ชื่อ - นามสกุล </div></td>
<td width="37%"><div align="center">การกระทำ</div></td>
</tr>
<?php /* -------- */ ?>
<?php
$s = trim($_POST[s]);
$Query = "";
if($s != ""){
switch($_POST[t]){
case "IDCard" : $Query = $db->query("SELECT * FROM ".User." WHERE IDCard LIKE "."'"."%".$s."%"."' "); break;
case "Name" : $Query = $db->query("SELECT * FROM ".User." WHERE Name LIKE "."'"."%".$s."%"."' "); break;
case "Lastname" : $Query = $db->query("SELECT * FROM ".User." WHERE Lastname LIKE "."'"."%".$s."%"."' "); break;
case "Address" : $Query = $db->query("SELECT * FROM ".User." WHERE Address LIKE "."'"."%".$s."%"."' "); break;
case "Username" : $Query = $db->query("SELECT * FROM ".User." WHERE Username LIKE "."'"."%".$s."%"."' "); break;
case "Phone" : $Query = $db->query("SELECT * FROM ".User." WHERE Phone LIKE "."'"."%".$s."%"."' "); break;
}
}else{
$Query = $db->query("
SELECT *
FROM ".User."
ORDER BY IDCard DESC
");
}
$sum = $db->rows($Query);
if($sum){
while($adduser = $db->fetch($Query)){
?>
<tr>
<td><?php echo $adduser->Name.' '.Lastname;?></td>
<td><div align="center">
[ <a href="index.php?f=adduser&action=open&id=<?php echo $adduse->IDCard;?>#showdata">เปิดดู</a> ] | [ <a href="index.php?f=adduser&action=edit&id=<?php echo $adduser->IDCard;?>">แก้ไข</a> ] | [ <a href="index.php?f=adduser&action=del&id=<?php echo $adduser->IDCard;?>" onClick="return confirm('คุณต้องการลบ <?php echo $adduser->Name;?> ?');">ลบ</a> ]
</div></td>
</tr>
<?php }
}else{ ?>
<tr>
<td colspan="2" class="center">ไม่พบรายการสมาชิก</td>
</tr>
<?php } ?>
<?php /* -------- */ ?>
</table>
</div></td>
</tr>
</table>
<div style="margin-top:50px;" class="dot-header">
<div style="margin-top:20px;">
<?php
if($action == "open"){
$m = $db->fetch($db->query("SELECT * FROM ".User." WHERE IDCard = '".$id."'"));
if($m->IDCard){
?>
<div class="center">
<div align="center" id="showdata">
<table width="500" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><div align="center">ข้อมูลสมาชิก</div></td>
</tr>
<tr>
<td width="129"><div align="right">รหัสประจำตัวประชาชน</div></td>
<td width="365"><div align="left"><?php echo $m->IDCard;?> </div></td>
</tr>
<tr>
<td><div align="right">ชื่อ</div></td>
<td><?php echo $m->Name;?></td>
</tr>
<tr>
<td><div align="right">นามสกุล</div></td>
<td><?php echo $m->Lastname;?></td>
</tr>
<tr>
<td><div align="right">ที่อยู่</div></td>
<td><?php echo $m->Address;?></td>
</tr>
<tr>
<td><div align="right">เบอร์โทรศัพท์</div></td>
<td><?php echo $m->Phone;?></td>
</tr>
<tr>
<td><div align="right">วัน/เดือน/ปีเกิด</div></td>
<td><?php echo $m->Birthday;?></td>
</tr>
<tr>
<td><div align="right">อายุ</div></td>
<td><?php echo $m->Age;?></td>
</tr>
<tr>
<td><div align="right">รหัสไปรษณีย์</div></td>
<td><?php echo $m->Zipcode;?></td>
</tr>
<tr>
<td><div align="right">Username</div></td>
<td><?php echo $m->Username;?></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><?php echo $m->Password;?></td>
</tr>
<tr>
<td><div align="right">การกระทำ</div></td>
<td>[ <a href="index.php?f=adduser&action=edit&id=<?php echo $m->IDCard;?>">แก้ไขข้อมูล</a> ] | [ <a href="index.php?f=member&action=del&id=<?php echo $m->IDCard;?>" onClick="return confirm('คุณต้องการลบ <?php echo $m->Name;?> ?');">ลบสมาชิก</a> ] </td>
</tr>
</table>
</div>
</div>
<?php
}else{ getJavaAlert("ไม่พบข้อมูลสมาชิก"); }
}else if($action == "add"){?>
<div align="center">
<form name="form2" method="post" action="index.php?f=adduser&action=saveadd">
<table width="500" border="0" cellspacing="5" cellpadding="5">
<tr>
<td colspan="2"><div align="center">กรอกข้อมูลสมาชิก</div></td>
</tr>
<tr>
<td><div align="right">รหัสบัตรประจำตัวประชาชน</div></td>
<td><input name="idcard" type="text" id="idcard" size="50"></td>
</tr>
<tr>
<td><div align="right">ชื่อ</div></td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td><div align="right">นามสกุล</div></td>
<td><input name="lastname" type="text" id="lastname" size="50"></td>
</tr>
<tr>
<td><div align="right">ที่อยู่</div></td>
<td><input name="address" type="text" id="address" size="50"></td>
</tr>
<tr>
<td><div align="right">เบอร์โทรศัพท์</div></td>
<td><input name="phone" type="text" id="phone" size="50"></td>
</tr>
<tr>
<td><div align="right">วัน/เดือน/ปีเกิด</div></td>
<td><input name="birthday" type="text" id="birthday" size="50"></td>
</tr>
<tr>
<td><div align="right">อายุ</div></td>
<td><input name="age" type="text" id="age" size="50"></td>
</tr>
<tr>
<td><div align="right">รหัสไปรษณีย์</div></td>
<td><input name="zipcode" type="text" id="zipcode" size="50"></td>
</tr>
<tr>
<td><div align="right">Usename</div></td>
<td><input name="username" type="text" id="username" size="50"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="password" type="text" id="password" size="50"></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="Submit2" value="เพิ่มสมาชิก"></td>
</tr>
</table>
</form>
</div>
<?php
}else if($action == "saveadd"){
$check = $db->fetch($db->query("
SELECT COUNT(IDCard) AS data
FROM ".User."
WHERE Username = '".trim($_POST[Username])."'
"));
if($check->data){
getJavaAlert("Username ซ้ำในระบบ");
}else{
$add = $db->add_db(User,array(
"IDCard" => trim($_POST[IDCard]),
"Lastname" => trim($_POST[Lastname]),
"Address" => trim($_POST[Address]),
"Phone"=> trim($_POST[Phone]),
"Birthday" => trim($_POST[Bithday]),
"Age" => trim($_POST[Age]),
"Zipcode" => trim($_POST[Zipcode]),
"Usename" => trim($_POST[Username]),
"Password" => trim($_POST[Password]),
));
if($add){
getJavaAlert("เพิ่มสมาชิกสำเร็จ",0);
}else{
getJavaAlert("เพิ่มสมาชิกล้มเหลว",0);
}
_go("index.php?f=adduser");
}
}else if($action == "edit"){
$m = $db->fetch($db->query("
SELECT *
FROM ".User."
WHERE IDCard = '".$id."'
"));
if($m->IDCard){
?>
<div align="center">
<form name="form3" method="post" action="index.php?f=adduser&action=saveedit&id=<?php echo $id;?>">
<table width="500" border="0" cellspacing="5" cellpadding="5">
<tr>
<td colspan="2"><div align="center">กรอกข้อมูลสมาชิก</div></td>
</tr>
<tr>
<td><div align="right">รหัสบัตรประจำตัวประชาชน</div></td>
<td><input name="idcard" type="text" id="idcard" size="50"></td>
</tr>
<tr>
<td><div align="right">ชื่อ</div></td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td><div align="right">นามสกุล</div></td>
<td><input name="lastname" type="text" id="lastname" size="50"></td>
</tr>
<tr>
<td><div align="right">ที่อยู่</div></td>
<td><input name="address" type="text" id="address" size="50"></td>
</tr>
<tr>
<td><div align="right">เบอร์โทรศัพท์</div></td>
<td><input name="phone" type="text" id="phone" size="50"></td>
</tr>
<tr>
<td><div align="right">วัน/เดือน/ปีเกิด</div></td>
<td><input name="birthday" type="text" id="birthday" size="50"></td>
</tr>
<tr>
<td><div align="right">อายุ</div></td>
<td><input name="age" type="text" id="age" size="50"></td>
</tr>
<tr>
<td><div align="right">รหัสไปรษณีย์</div></td>
<td><input name="zipcode" type="text" id="zipcode" size="50"></td>
</tr>
<tr>
<td><div align="right">Usename</div></td>
<td><input name="username" type="text" id="username" size="50"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="password" type="text" id="password" size="50"></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="Submit2" value="แก้ไขข้อมูล"></td>
</tr>
</table>
</form>
</div>
<?php
}else{ getJavaAlert("ไม่พบสมาชิก"); }
}else if($action == "saveedit"){
if($id){
$save = $db->update_db(_MEMBER,array(
"IDCard" => trim($_POST[IDCard]),
"Lastname" => trim($_POST[Lastname]),
"Address" => trim($_POST[Address]),
"Phone"=> trim($_POST[Phone]),
"Birthday" => trim($_POST[Bithday]),
"Age" => trim($_POST[Age]),
"Zipcode" => trim($_POST[Zipcode]),
"Usename" => trim($_POST[Username]),
"Password" => trim($_POST[Password]),
),"IDCard = '".$id."'");
if($save){
getJavaAlert("แก้ไขข้อมูลสำเร็จ",0);
}else{
getJavaAlert("แก้ไขข้อมูลล้มเหลว",0);
}
}
_go("index.php?f=adduser");
}else if($action == "del"){
$del = $db->del(User,"IDCard = '".$id."'");
if($del){
getJavaAlert("ลบข้อมูลสำเร็จ",0);
}else{
getJavaAlert("ลบข้อมูลล้มเหลว",0);
}
_go("index.php?f=adduser");
}
?>
</div>
</div>
แลัวพอรันบนหน้าบราวเซอร์นะค่ะมันขึ้น Error แบบนี้ค่ะ Fatal error: Call to a member function query() on a non-object in C:\AppServ\www\test\adduser.php on line 42 งงอ่ะค่ะ ช่วยทีนะค่ะTag : PHP
Date :
2011-07-02 15:45:57
By :
modzaa07
View :
948
Reply :
1
Load balance : Server 04