|
|
|
สอบถาม หน่อย ครับ พอดีผมเคยดูกระทู้นึงในเพจนี้นะครับ ที่เกี่ยวกับ เลขทศนิยมและลูกน้ำอะครับ ผมลองทำตามแล้ว แต่พอ Insert เข้าฐานข้อมูล มันตัดเลขหลังลูกน้ำออกนะครับ เช่น 1,000.00 ก็จะเข้า แค่ 1 อะครับ |
|
|
|
|
|
|
|
Code (PHP)
<?php require_once('Connections/db_rice.php'); ?>
<?php include("dw-upload.inc.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO product (ProductName, RiceSeeDid, price, Productimg) VALUES (%s, %s, %s, %s )",
GetSQLValueString($_POST['ProRicE'], "text"),
GetSQLValueString($_POST['ProRicESeeD'], "int"),
GetSQLValueString($_POST['txtpice'], "double"),
GetSQLValueString(dwUpload($_FILES["pic_products"]), "text"));
mysql_select_db($database_db_rice, $db_rice);
$Result1 = mysql_query($insertSQL, $db_rice) or die(mysql_error());
$insertGoTo = "searchProduct.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_db_rice, $db_rice);
$query_Recordset1 = "SELECT * FROM riceseed";
$Recordset1 = mysql_query($query_Recordset1, $db_rice) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_db_rice, $db_rice);
$query_Recordset2 = "SELECT * FROM product";
$Recordset2 = mysql_query($query_Recordset2, $db_rice) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="templates/main.css"/>
<style type="text/css">
.container #form1 table {
text-align: left;
}
</style>
<title>Rice Mart</title>
</head>
<body>
<div class="container">
<?php require_once("templates/header.inc.php")?>
<?php require_once("templates/sidenav4.inc.php")?>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<h1>เพิ่มข้อมูลสินค้า </h1>
<table width="42%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<th bgcolor="#CCCCCC" scope="row">ชื่อสินค้า</th>
<td bgcolor="#CCCCCC"><input name="ProRicE" type="text" id="ProRicE" size="25" /></td>
</tr>
<tr>
<th bgcolor="#CCCCCC" scope="row">
<label for="ProRicESeeD2">พันธุ์ข้าว</label></th>
<td bgcolor="#CCCCCC"><select name="ProRicESeeD" id="ProRicESeeD">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['RicESeedId']?>"><?php echo $row_Recordset1['RicESeedDesc']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select></td>
</tr>
<tr>
<th bgcolor="#CCCCCC" scope="row"><label for="txtpice2">ราคาสินค้า</label> </th>
<td bgcolor="#CCCCCC"><input name="txtpice" type="text" id="txtpice" style="text-align:right;padding-right:2px;" size="25"/on onchange ="JavaScript:chkNum(this)"onkeyup="if(isNaN(this.value)){ alert('กรุณากรอกตัวเลข'); this.value='';}">
บาท </td>
</tr>
<tr>
<th bgcolor="#CCCCCC" scope="row">รูปภาพ</th>
<td bgcolor="#CCCCCC"><input name="pic_products" type="file" class="container" id="pic_products" /></td>
</tr>
<tr>
<th bgcolor="#CCCCCC" scope="row"> </th>
<td bgcolor="#CCCCCC"><input type="submit" name="InRicESeeD" id="InRicESeeD" value="เพิ่มข้อมูล" onclick="return confirm('ท่านต้องที่จะเพิ่มหรือไม่')"/></td>
</tr>
</table>
<p> </p>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<?php require_once("templates/footer.inc.php")?>
</div>
</body>
<script language="JavaScript">
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function chkNum(ele)
{
var num = parseFloat(ele.value);
ele.value = addCommas(num.toFixed(2));
}
</script>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
Tag : PHP, MySQL, CSS, HTML5, XAMPP
|
|
|
|
|
|
Date :
2017-06-18 20:38:19 |
By :
bassnaruto |
View :
712 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ฟิลด์ ที่เก็บข้อมูลมี type เป็นอะไรครับ
|
|
|
|
|
Date :
2017-06-19 04:53:57 |
By :
deawx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เวลานำเข้าให้ตัด คอมม่า ออกก่อน
|
|
|
|
|
Date :
2017-06-19 08:30:28 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|