|
|
|
ถามเรื่องการตรวจสอบค่าว่างของ $_post ว่าถ้าเป็น ว่างให้ใส่ 0 แทนแล้วบันถึงลง DB |
|
|
|
|
|
|
|
ตรงช่องที่รับค่าครับอยากให้ตรวจสอบค่าว่าง ว่าถ้าค่าเป็นว่าง ให้ใ่ส่ 0 เข้าไปแทน
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">อ้อม</td>
<td><input type="text" name="aom" value="" size="32" /></td>
</tr>
รับค่าของช่องนี้ครับ
Code (PHP)
<?php require_once('Connections/orderrm.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 `order` (`date`, namejob, customer, itemcode, papername, rp, so, price, amount, total, aom, ae, poo, ple, ked, fon, mol, doung) VALUES (NOW(), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['namejob'], "text"),
GetSQLValueString($_POST['customer'], "text"),
GetSQLValueString($_POST['itemcode'], "text"),
GetSQLValueString($_POST['papername'], "text"),
GetSQLValueString($_POST['rp'], "text"),
GetSQLValueString($_POST['so'], "text"),
GetSQLValueString($_POST['price'], "int"),
GetSQLValueString($_POST['amount'], "int"),
GetSQLValueString($_POST['total'], "int"),
GetSQLValueString($_POST['aom'], "int"),
GetSQLValueString($_POST['ae'], "int"),
GetSQLValueString($_POST['poo'], "int"),
GetSQLValueString($_POST['ple'], "int"),
GetSQLValueString($_POST['ked'], "int"),
GetSQLValueString($_POST['fon'], "int"),
GetSQLValueString($_POST['mol'], "int"),
GetSQLValueString($_POST['doung'], "int"));
mysql_select_db($database_orderrm, $orderrm);
$Result1 = mysql_query($insertSQL, $orderrm) or die(mysql_error());
$insertGoTo = "insertData.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_orderrm, $orderrm);
$query_Recordset1 = "SELECT * ,(aom+ae+poo+ple+ked+fon+mol+doung) AS total FROM `order`";
$Recordset1 = mysql_query($query_Recordset1, $orderrm) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_query("SET character_set_results=UTF8");
mysql_query("SET character_set_client=UTF8");
mysql_query("SET character_set_connection=UTF8");
?>
<!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" />
<title>เพิ่มข้อมูล</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr align="center" valign="baseline" bgcolor="#66CCFF">
<td nowrap="nowrap"> </td>
<td>บันทึกรายการ</td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">ชื่องาน</td>
<td><input type="text" name="namejob" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">ชื่อลูกค้า</td>
<td><input type="text" name="customer" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">Itemcode:</td>
<td><input type="text" name="itemcode" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">ชื่อกระดาษ</td>
<td><input type="text" name="papername" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">RP:</td>
<td><input type="text" name="rp" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">SO:</td>
<td><input type="text" name="so" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">ราคาต่อหน่วย</td>
<td><input type="text" name="price" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">จำนวนชิ้นงาน:</td>
<td><input type="text" name="amount" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF"> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">อ้อม</td>
<td><input type="text" name="aom" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">เอ๋</td>
<td><input type="text" name="ae" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">ปู</td>
<td><input type="text" name="poo" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">เปิ้ล</td>
<td><input type="text" name="ple" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">เกต</td>
<td><input type="text" name="ked" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">ฝน</td>
<td><input type="text" name="fon" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">มล</td>
<td><input type="text" name="mol" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF">อุ๋ย</td>
<td><input type="text" name="doung" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="center" nowrap="nowrap" bgcolor="#66CCFF"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p><br />
</p>
<table border="1" align="center" cellpadding="1" cellspacing="1">
<tr align="center" bgcolor="#66CCFF">
<td>วันที่</td>
<td>ชื่องาน</td>
<td>ชื่อลูกค้า</td>
<td>itemcode</td>
<td>ชื่อกระดาษ</td>
<td>RP</td>
<td>SO</td>
<td>ราคาต่อชิ้น</td>
<td>จำนวนชิ้น</td>
<td>รวม</td>
<td>อ้อม</td>
<td>เอ๋</td>
<td>ปู</td>
<td>เปิ้ล</td>
<td>เกต</td>
<td>ฝน</td>
<td>มล</td>
<td>อุ๋ย</td>
<td>สถานนะซื้อ</td>
<td>วันที่สั่งซื้อ</td>
<td>สถานะของเข้า</td>
<td>วันที่รับของเข้า</td>
</tr>
<?php do { ?>
<tr bgcolor="#CCFF99">
<td><?php echo $row_Recordset1['date']; ?></td>
<td><?php echo $row_Recordset1['namejob']; ?></td>
<td><?php echo $row_Recordset1['customer']; ?></td>
<td><?php echo $row_Recordset1['itemcode']; ?></td>
<td><?php echo $row_Recordset1['papername']; ?></td>
<td><?php echo $row_Recordset1['rp']; ?></td>
<td><?php echo $row_Recordset1['so']; ?></td>
<td><?php echo $row_Recordset1['price']; ?></td>
<td><?php echo $row_Recordset1['amount']; ?></td>
<td><?php echo $row_Recordset1['total']; ?></td>
<td><?php echo $row_Recordset1['aom']; ?></td>
<td><?php echo $row_Recordset1['ae']; ?></td>
<td><?php echo $row_Recordset1['poo']; ?></td>
<td><?php echo $row_Recordset1['ple']; ?></td>
<td><?php echo $row_Recordset1['ked']; ?></td>
<td><?php echo $row_Recordset1['fon']; ?></td>
<td><?php echo $row_Recordset1['mol']; ?></td>
<td><?php echo $row_Recordset1['doung']; ?></td>
<td><?php echo $row_Recordset1['buy']; ?></td>
<td><?php echo $row_Recordset1['buydate']; ?></td>
<td><?php echo $row_Recordset1['import']; ?></td>
<td><?php echo $row_Recordset1['importdate']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Tag : PHP, MySQL, HTML5, XAMPP
|
|
|
|
|
|
Date :
2017-08-23 10:44:22 |
By :
bondhams |
View :
1255 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สร้างเงื่อนไข if esle
if($_post['xxxx'] = "") {
$xxxx = "0";
}else{
$xxxx = $_post['xxxx'];
}
|
|
|
|
|
Date :
2017-08-23 13:51:07 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองแล้วมันก็ขึ้นแบบนี้ครับ
Notice: Undefined index: total in C:\xampp\htdocs\order\insertData.php on line 100
Column 'aom' cannot be null
|
|
|
|
|
Date :
2017-08-25 17:09:32 |
By :
bondhams |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GetSQLValueString(0 . $_POST['aom'], "int"),
|
|
|
|
|
Date :
2017-08-26 06:50:06 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|