|
|
|
ช่วยแก้โค้ดหน่อยค่ะ เพิ่มข้อมูล.. ตอนแรกเป็น textbox เปลี่ยนเป็นแบบ drop down แล้วข้อมูลไม่เข้า database ค่ะ TT |
|
|
|
|
|
|
|
ตรง TypeID กับ ShopID ค่ะ
ขอบคุณล่วงหน้าค่ะ TT
Code (PHP)
<?php
include "connectDB/connectdb.php";
?>
<!--เพิ่มรูปภาพ-->
<?php
if(isset($_POST['submit'])){
//print_r(array( 'post'=>$_REQUEST, 'file'=>$_FILES )); exit; // ตรวจสอบข้อมูลเบื้องต้น ใช้งานจริงมาร์ค
$filetmp = $_FILES["file_img"]["tmp_name"];
$filename = $_FILES["file_img"]["name"];
$filetype = $_FILES["file_img"]["type"];
$filepath = "images2/".$filename;
move_uploaded_file($filetmp,$filepath);
$sql = "INSERT INTO item (ItemName,ItemCost,ItemNamePic,ItemPic,ItemTypePic,ItemDesc,TypeID,ShopID) VALUES ('".$_POST["itemname"]."','".$_POST["itemcost"]."','$filename','$filepath','$filetype','".$_POST["itemdesc"]."')";
//,'".$_POST["itemtypeid"]."','".$_POST["itemshopid"]."'
$result = mysql_query($sql);
}
?>
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="script.js"></script>
<title>NMNS Coffee Shops Home</title>
</HEAD>
<body bgcolor="FF82AB" >
<div id='cssmenu'>
<ul>
<li><form method="post" action="?">
<p><input type="text" name="search" class="search"/> <input type="submit" value="Search" class="button" /></p></form></li>
<li><a href='login.php'>LOGIN</a></li>
<li><a href='contact.php'>CONTACT |</a></li>
<li><a href='gallary.php'>GALLARY |</a></li>
<li><a href='pages.php'>PAGES |</a></li>
<li><a href='index.php'>HOME |</a></li>
</ul>
</div>
<br>
<div id='boxPre'>
<!-ตารางใหญ่-->
<center>
<TABLE width="90%">
<tr> <center>
<td bgcolor="#e11375" width="80%" border="3" style="
padding: 15px;
-moz-border-radius: 15px;
-khtml-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;">
<!--เพิ่มร้านค้า!-->
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="page-header">
<h3>เพิ่มรูปภาพ</h3><a href="gallary.php">กลับสู่หน้าหลัก</a>
</div>
<form class="form-horizontal" method="post" enctype="multipart/form-data" >
<div class="form-group">
<label class="col-sm-3 control-label">ชื่อ :</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="itemname" placeholder="ชื่อ" required>
<span id="error_f"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">ราคา :</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="itemcost" placeholder="ราคา" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">รูปภาพ :</label>
<div class="col-sm-9">
<!-- form action="add_shop.php" method="post" enctype="multipart/form-data" -->
<input type="file" name="file_img" />
<!-- input type="submit" name="btn_upload" value="Upload">
</form -->
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">รีวิว :</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="itemdesc" placeholder="รีวิว" required>
</div>
</div>
<!--<div class="form-group">
<label class="col-sm-3 control-label">TypeID :</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="itemtypeid" placeholder="รหัสประเภท" required>
</div>
</div>-->
<div class="form-group">
<label class="col-sm-3 control-label">Type</label>
<div class="col-sm-8">
<select class="form-control" id="type">
<option>เลือกประเภท</option>
<?php
$geography1 = mysql_query("select * from type");
while($row = mysql_fetch_array($geography1)){
echo "<option value=".$row['TypeID'].">".$row['TypeName']."</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Shop</label>
<div class="col-sm-8">
<select class="form-control" id="shop">
<option>เลือกร้าน</option>
<?php
$geography2 = mysql_query("select * from shop");
while($row = mysql_fetch_array($geography2)){
echo "<option value=".$row['ShopID'].">".$row['ShopName']."</option>";
}
?>
</select>
</div>
</div>
<!--<div class="form-group">
<label class="col-sm-3 control-label">Shop</label>
<div class="col-sm-8">
<select class="form-control" id="shop">
<option value="0">เลือกร้าน</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">ShopID :</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="itemshopid" placeholder="รหัสร้าน" required>
</div>
</div>-->
<div class="form-group">
<div class="col-sm-3">
<button type="submit" name="submit" id="submit" class="btn btn-default" value="Upload">Save</button>
</div>
</div>
</form>
</div>
</div>
</div>
</tr>
</div>
</table>
</center>
<!--ถ้าว่าง-->
<script type="text/javascript">
var use_ajax = false;
function is_blank( obj){
if( obj.value.trim()) return false;
alert('กรุณากรอกข้อมูลให้ครบ'); obj.focus(); return true;
}
$(document).ready(function(){
$('form').on('submit',function(){
if( is_blank(this.itemname)) return false;
if( is_blank(this.itemcost)) return false;
if( is_blank(this.itemdesc)) return false;
///////////////////////////////// กรณีไม่ใช้ ajax
//if( !use_ajax ) return true;
///////////////////////////////// หรือใช้ ajax
var url = "save_item.php";
var datas = $('form').serialize();
$.post(url,datas,function(data){
$.ajax({ type: 'POST', data: $('form').serialize() })
.done(function(data){
alert(data);
window.location.href = "pages.php";
})
})
});
</script>
</BODY>
</HTML>
Tag : PHP, MySQL, HTML/CSS, JavaScript
|
|
|
|
|
|
Date :
2015-12-13 17:11:59 |
By :
ryomaconz |
View :
829 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select option attribute name missing
|
|
|
|
|
Date :
2015-12-13 17:34:46 |
By :
noMerzy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code
019.
$sql = "INSERT INTO item (
ItemName, #1
ItemCost, #2
ItemNamePic, #3
ItemPic, #4
ItemTypePic, #5
ItemDesc, #6
TypeID, #7
ShopID #8
) VALUES (
'".$_POST["itemname"]."', #1
'".$_POST["itemcost"]."', #2
'$filename', #3
'$filepath', #4
'$filetype', #5
'".$_POST["itemdesc"]."' #6
)";
|
|
|
|
|
Date :
2015-12-13 19:43:50 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|