|
 |
|
ทำยังไงไม่ให้ค่าที่ติดลบลง database ได้คับช่วยที่คับด่วนมาก |
|
 |
|
|
 |
 |
|
คือค่า P_Number(จำนวน) และ P_Price(ราคา)มันต้องติดลบไม่ได้คับ
Code (PHP)
<!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>Untitled Document</title>
</head>
<center>
<body>
<form name="insert_tool" method="post" action="../admin/check_insert_tool.php" enctype="multipart/form-data">
<table width="320" border="1">
<tr>
<td width="95" align="center">รหัสสินค้า</td>
<td width="200" align="center"><input name="txtProduct1" type="text" size="20" ></td>
</tr>
<tr>
<td align="center">ชื่อสินค้า</td>
<td align="center"><input name="txtProduct2" type="text" size="20" ></td>
</tr>
<tr>
<td align="center">จำนวน</td>
<td align="center"><input name="txtProduct3" type="text" size="7" />
<select name="txtProduct7" id="txtProduct7" size="0">
<option value="กระสอบ">กระสอบ</option>
<option value="ขวด">ขวด</option>
<option value="อัน">อัน</option>
</select></td>
</tr>
<tr>
<td align="center">ราคา</td>
<td align="center"><input name="txtProduct4" type="text" size="20"></td>
</tr>
<tr>
<td align="center">ประเภท</td>
<td align="center"><font size="3">อุปกรณ์</font><select name="txtProduct5" id="txtProduct5" style="display:none">
<option value="tool">อุปกรณ์</option>
</select>
</td>
</tr>
<tr>
<td align="center">คุณสมบัติ</td>
<td align="center"><textarea name="txtProduct6" id="txtAddress" rows="8" cols="30"></textarea></td>
</tr>
<tr>
<td align="center">รูปภาพ</td>
<td align="center"><input type="file" name="filUpload" ></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Cancel">
</form>
</body>
</center>
</html>
Code (PHP)
<?php
ob_start();
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
if(trim($_POST["txtProduct1"]) == "")
{
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('คุณไม่ได้กรอกรหัสสินค้า') </script> ";
echo"<meta http-equiv='refresh' content='0;url=../customer/admin.php?id=5'>";
exit();
}
if(trim($_POST["txtProduct2"]) == "")
{
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('คุณไม่ได้กรอกชื่อสินค้า') </script> ";
echo"<meta http-equiv='refresh' content='0;url=../customer/admin.php?id=5'>";
exit();
}
if(trim($_POST["txtProduct3"]) == "")
{
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('คุณไม่ได้กรอกจำนวน่') </script> ";
echo"<meta http-equiv='refresh' content='0;url=../customer/admin.php?id=5'>";
exit();
}
if(trim($_POST["txtProduct4"]) == "")
{
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('คุณไม่ได้กรอกราคา') </script> ";
echo"<meta http-equiv='refresh' content='0;url=../customer/admin.php?id=5'>";
exit();
}
if(trim($_POST["txtProduct6"]) == "")
{
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('คุณไม่ได้กรอกคุณสมบัติ') </script> ";
echo"<meta http-equiv='refresh' content='0;url=../customer/admin.php?id=5'>";
exit();
}
if(($_POST["txtProduct3"]) > 1)
{
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('ต้องใส่จำนวนเต็มบวก') </script> ";
echo"<meta http-equiv='refresh' content='0;url=../customer/admin.php?id=5'>";
exit();
}
if(copy($_FILES["filUpload"]["tmp_name"],"../admin/product_all/".$_FILES["filUpload"]["name"]))
{
echo "<script language='javascript'>alert('complete');history.back();window.location='../admin/admin.php?id=2';</script>";
//*** Insert Record ***//
include('config.inc.php');
$strSQL = "INSERT INTO product ";
$strSQL .="(ID_Product,P_name,P_Number,P_Price,P_Files,P_Type,P_Property,P_X) VALUES ('".$_POST["txtProduct1"]."','".$_POST["txtProduct2"]."',
'".$_POST["txtProduct3"]."','".$_POST["txtProduct4"]."','".$_FILES["filUpload"]["name"]."','".$_POST["txtProduct5"]."'
,'".$_POST["txtProduct6"]."','".$_POST["txtProduct7"]."')";
$objQuery = mysql_query($strSQL);
}
else{
echo "<script language='javascript'>alert('คุณไม่ได้ใส่รูปภาพ');history.back();window.location='../admin/admin.php?id=5';</script>";
}
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2013-09-23 15:12:18 |
By :
woraman |
View :
1520 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ javascript เช็คตอนบันทึกครับ
ถ้าค่ามันน้อยกว่า 0 หรือเงื่อนไขอะไรก็ว่าไป
|
 |
 |
 |
 |
Date :
2013-09-23 15:23:43 |
By :
anotherdie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
if(($_POST["txtProduct3"]) > 1)
สมมุติ เค้ากรอก -5 เงื่อนไขเป็นจริงหรือเท็จ
|
 |
 |
 |
 |
Date :
2013-09-23 15:33:29 |
By :
anotherdie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมคุณไม่ตั้งชื่อ ตัวแปร name ก่อนทำการ action
|
 |
 |
 |
 |
Date :
2013-09-23 15:38:00 |
By :
Ex-[S]i[L]e[N]t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|