|
 |
|
ช่วยดูโค็ตให้หน่อย เกี่ยวการเพิ่มข้อมูลลงใน DB ทำอยู่ในหน้าเดียวกันหมด |
|
 |
|
|
 |
 |
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
.style2 {
font-family: "Times New Roman", Times, serif;
font-weight: bold;
}
-->
</style>
</head>
<body>
<FORM ACTION = "<?=$_SERVER['SCRIPT_NAME']?>" METHOD="GET">
<table width="368" height="152" border="1">
<tr>
<td width="86"><h5 class="style2">รหัสสินค้า :</h5></td>
<td width="266"><label>
<input type="text" name="id_product" id="id_product" />
</label></td>
</tr>
<tr>
<td><h5 class="style2">ชื่อสินค้า :</h5></td>
<td><label>
<input name="name_product" type="text" id="name_product" size="40" />
</label></td>
</tr>
<tr>
<td><h5 class="style2">ราคา :</h5></td>
<td><label>
<input type="text" name="price" id="price" />
</label></td>
</tr>
<tr>
<td height="23"><h5 class="style2">จำนวนสินค้า :</h5></td>
<td><label>
<input type="text" name="balance" id="balance" />
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button2" id="button2" value="cencel" />
</label></td>
</tr>
</table>
</form>
<?php
require('conn_mysql.php');
$id_product = $_POST['id_product'];
$name_product = $_POST['name_product'];
$price = $_POST['price'];
$balance = $_POST['balance'];
$sql = "INSERT INTO product(id_product,name_product,price,balance) values('$id_product','$name_product','$price','$balance')";
if (mysql_query($sql,$conn)) {
echo "เพิ่มข้อมูลเรียบร้อยแล้ว";
} else {
echo "ไม่สามารถเพิ่มข้อมูลได้",mysql_error();
}
mysql_close ($conn)
?>
พอรันก็ มีข้อความว่า เพิ่มข้อมูลเรียบร้อยแล้ว งงมาก ยังไม่เพิ่มเลย แต่พอเพิ่มก็ไม่มีข้อมูล ใน DB
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2010-08-29 21:12:14 |
By :
beer656 |
View :
1152 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา if มาเช็คการรับค่าจากฟอร์ม เช่น if(submit){}
|
 |
 |
 |
 |
Date :
2010-08-29 22:08:54 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองนะครับ
$sql=mysql_query("insert into product(id_product,name_product,price,balance)
values('',$id_product,'$name_product','$price','$balance')");
ผมว่ามันน่าจะได้ยังงีนะ
|
 |
 |
 |
 |
Date :
2010-09-30 14:17:02 |
By :
ชาละวัน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|