ระบบ เพิ่ม ลบ แก้ไขข้อมูลลง database ไม่ได้ ไม่รู้ว่าผิดตรงไหน หาบัคไม่เจอครับ
ผมได้ระบบมาแก้อีกที ตอนแรกระบบใช้งานได้ปกติครับ แต่ไม่รู้ว่าไปทำผิดส่วนไหนเลยใช้งานไม่ได้ ไม่ทราบว่าพอจะช่วยดูให้หน่อยนะครับ
Code (adddata.php)
<div class="contain">
<h2 class="sub-header">เพิ่มข้อมูลหนังสือใหม่</h2>
<form role="form">
<div class="form-group">
<label>ชื่อหนังสือ</label>
<input type="text" id="name" class="form-control">
</div>
<div class="form-group">
<label>Details</label>
<textarea id="details" class="form-control"></textarea>
</div>
<div class="form-group">
<label>Image</label>
<input type="text" id="image" class="form-control">
</div>
<div class="form-group">
<label>Price</label>
<input type="text" id="price" class="form-control">
</div>
<div class="form-group">
<label>Description</label>
<textarea id="body"></textarea>
</div>
<div class="form-group">
<label>หมวดหมู่</label>
<select id="cate" class="select-type">
<?php
$category = "SELECT * FROM book_category";
$category_result = $mydb->runQuery($category);
while($category_row = mysqli_fetch_assoc($category_result)){
?>
<option value="<?php echo $category_row['category_cid']?>" selected="selected"><?php echo $category_row['category_name']?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>URL</label>
<input type="text" id="keyword" class="form-control">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" id="contact" class="form-control">
</div>
<button type="submit" class="btn btn-default" onclick="DataAdd(); return false">เพิ่ม</button>
</form>
</div>
Code (editdata.php)
<div class="contain">
<h2 class="sub-header">แก้ไขข้อมูลหนังสือ</h2>
<?php
@$editid = $_GET['edit-id'];
if($editid)
{
$data = "SELECT * FROM book_data WHERE book_did = '".$editid."'";
$data_result = $mydb->runQuery($data);
$data_row = mysqli_fetch_assoc($data_result);
?>
<form role="form">
<div class="form-group">
<label>ชื่อหนังสือ</label>
<input type="text" id="name" class="form-control" value="<?php echo $data_row['shop_name']?>">
</div>
<div class="form-group">
<label>Details</label>
<textarea id="details" class="form-control"><?php echo $data_row['shop_details']?></textarea>
</div>
<div class="form-group">
<label>Image</label>
<input type="text" id="image" class="form-control" value="<?php echo $data_row['shop_image']?>">
</div>
<div class="form-group">
<label>Price</label>
<input type="text" id="price" class="form-control" value="<?php echo $data_row['shop_price']?>">
</div>
<div class="form-group">
<label>Description</label>
<textarea id="body"><?php echo $data_row['shop_desc']?></textarea>
</div>
<div class="form-group">
<label>หมวดหมู่</label>
<select id="cate" class="select-type">
<?php
$category = "SELECT * FROM book_category";
$category_result = $mydb->runQuery($category);
while($category_row = mysqli_fetch_assoc($category_result)){
?>
<option value="<?php echo $category_row['category_cid']?>" <?php if($category_row['category_cid'] == $data_row['book_category']){ echo "selected='selected'";}?>><?php echo $category_row['category_name']?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>URL</label>
<input type="text" id="keyword" class="form-control" value="<?php echo $data_row['shop_keyword']?>">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" id="contact" class="form-control" value="<?php echo $data_row['shop_contact']?>">
</div>
<input type="hidden" id="did" value="<?php echo $data_row['book_did']?>">
<button type="submit" class="btn btn-default" onclick="DataEdit(); return false">แก้ไข</button>
<button type="submit" class="btn btn-default" onclick="DataDel(); return false">ลบ</button>
</form>
<?php
} else {
$data = "SELECT * FROM book_data ORDER BY book_did DESC";
$data_result = $mydb->runQuery($data);
while($data_row = mysqli_fetch_assoc($data_result)){
$category = "SELECT * FROM book_category WHERE category_cid = '".$data_row['book_category']."'";
$category_result = $mydb->runQuery($category);
$category_row = mysqli_fetch_assoc($category_result);
?>
<div>[<a href="?sec=data&insub=data-edit&edit-id=<?php echo $data_row['book_did'];?>"> แก้ไข</a>] <?php echo $data_row['shop_name'];?> (<?php echo $category_row['category_name']?>)</div>
<?php
}
}
?>
</div>
Code (process.php)
<?php
session_start();
require_once "../lib/webconfig.php";
require_once "../func/database.class.php";
require_once "plugin/mail/mail.php";
date_default_timezone_set('Asia/Bangkok');
$mydb = new Database();
@$act = $mydb->clearText($_POST['action']);
if($act == "addcart"){
$did = $mydb->clearText($_POST['did']);
if(!isset($_SESSION['line'])){
$_SESSION['line'] = 0;
$_SESSION['book_data'][0] = $did;
$_SESSION['qty'][0] = 1;
} else {
$key = array_search($did,$_SESSION['book_data']);
if((string)$key != ""){
$_SESSION['qty'][$key] = $_SESSION['qty'][$key] + 1;
} else {
$_SESSION['line'] = $_SESSION['line'] + 1;
$line = $_SESSION['line'];
$_SESSION['book_data'][$line] = $did;
$_SESSION['qty'][$line] = 1;
}
}
}
if($act == "delfmcart"){
$i = $mydb->clearText($_POST['i']);
$_SESSION['book_data'][$i] = "";
$_SESSION['qty'][$i] = "";
}
if($act == "order"){
$did = $mydb->clearText($_POST['did']);
$ip = $_SERVER['REMOTE_ADDR'];
$name = $mydb->clearText($_POST['name']);
$email = $mydb->clearText($_POST['email']);
$tel = $mydb->clearText($_POST['tel']);
$invoice = strrev(time());
$sum = "";
$product = "";
$date = date("Y-m-d");
if($did){
$book_did = explode(",",$did);
for($i=0;$i<count($book_did);$i++){
$insert = "INSERT INTO shop_order (book_did,order_name,order_email,order_tel,order_invoice,order_ipaddress) VALUES ('".$book_did[$i]."','".$name."','".$email."','".$tel."','".$invoice."','".$ip."')";
$insert_result = $mydb->runQuery($insert);
if($act == "adminlog"){
$user = $mydb->clearText($_POST['user']);
$pass = $mydb->clearText($_POST['pass']);
if($user == "admin" && $pass == "admin"){
$_SESSION['Admin'] = true;
echo "Login Ok.";
}
}
if(@$_SESSION['Admin']){
if($act == "adddata"){
$name = $mydb->clearText($_POST['name']);
$details = $mydb->clearText($_POST['details']);
$image = $mydb->clearText($_POST['image']);
$price = $mydb->clearText($_POST['price']);
$desc = $mydb->clearText($_POST['desc']);
$cate = $mydb->clearText($_POST['cate']);
$keyword = $mydb->clearText($_POST['keyword']);
$contact = $mydb->clearText($_POST['contact']);
$insert = "INSERT INTO book_data (shop_name,shop_details,shop_image,shop_price,shop_desc,book_category,shop_keyword,shop_contact) VALUES ('".$name."','".$details."','".$image."','".$price."','".$desc."','".$cate."','".$keyword."','".$contact."')";
$insert_result = $mydb->runQuery($insert);
if($insert_result){
echo "เพิ่มข้อมูลหนังสือใหม่สำเร็จ";
} else {
echo "เพิ่มข้อมูลหนังสือใหม่ล้มเหลว";
}
}
if($act == "editdata"){
$name = $mydb->clearText($_POST['name']);
$details = $mydb->clearText($_POST['details']);
$image = $mydb->clearText($_POST['image']);
$price = $mydb->clearText($_POST['price']);
$desc = $mydb->clearText($_POST['desc']);
$cate = $mydb->clearText($_POST['cate']);
$keyword = $mydb->clearText($_POST['keyword']);
$contact = $mydb->clearText($_POST['contact']);
$did = $mydb->clearText($_POST['did']);
$update = $mydb->runQuery("UPDATE book_data SET shop_name = '".$name."' , shop_details = '".$details."' , shop_image = '".$image."' , shop_price = '".$price."' , shop_desc = '".$desc."' , book_category = '".$cate."' , shop_keyword = '".$keyword."' , shop_contact = '".$contact."' WHERE book_did = '".$did."'");
if($update){
echo "ทำการแก้ไขมูลหนังสือใหม่สำเร็จ";
} else {
echo "ทำการแก้ไขมูลหนังสือใหม่ล้มเหลว";
}
}
if($act == "deldata"){
$did = $mydb->clearText($_POST['did']);
$delete = $mydb->runQuery("DELETE FROM book_data WHERE book_did = '".$did."'");
if($delete){
echo "ทำการลบมูลหนังสือสำเร็จ";
} else {
echo "ทำการลบมูลหนังสือล้มเหลว";
}
}
Code (shop.sql)
-- Table structure for table `book_data`
--
CREATE TABLE IF NOT EXISTS `book_data` (
`book_did` int(11) NOT NULL,
`shop_name` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`shop_details` varchar(2000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`shop_desc` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`shop_category` int(11) NOT NULL,
`shop_image` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`shop_price` int(11) NOT NULL,
`shop_keyword` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`shop_contact` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `book_data`
--
INSERT INTO `book_data` (`book_did`, `shop_name`, `shop_details`, `shop_desc`, `shop_category`, `shop_image`, `shop_price`, `shop_keyword`, `shop_contact`) VALUES
(1, 'BBS V2', 'xzcasdqwrwqrwqewqewqewqewqewqewqewqewqewqeqwewqewqewqewqeweqwqaszxcxzcxzcxzc', '<p>asdsadsxzcxzasfqwrqwwqtqw ewq ewq e wqe wq e as xc b vc r e retqwewq</p>', 1, 'http://www.hollandlift.com/wp-content/themes/hollandlift/assets/images/no_image.jpg', 5000, 'test', ''),
(2, 'BBS V1', '', 'qweqwecxzas\r\nwqrwqrqweqw\r\nczxczx', 1, '', 3000, '', ''),
(3, 'Shop Script', 'asd', '<p>qweasxzcrqwrwq ewqewqzxc</p>', 1, 'http://www.hollandlift.com/wp-content/themes/hollandlift/assets/images/no_image.jpg', 2000, 'eee', ''),
(4, 'dfewrqwwq', 'test', '<p>czxasqwe</p>', 1, 'http://cdn.akamai.steamstatic.com/steam/apps/239220/capsule_616x353.jpg?t=1421543006', 1000, 'test', ''),
(9, 'qwewq', 'easdsad', '', 6, '1', 10000, 'ads', 'wqrwq'),
(10, 'test', 'test', '', 1, 'test', 1000, 'test', '');
Tag : PHP, MySQL
ประวัติการแก้ไข 2015-04-24 16:59:26
Date :
2015-04-24 16:55:10
By :
indy
View :
1361
Reply :
1
Code เยอะดีน่ะครับ ไม่ได้ส่วนไหน ลองใช้ or die(mysql_error()) ทำการดักจับ Error ก็ได้ครับ
Date :
2015-04-24 17:24:52
By :
mr.win
Load balance : Server 00