|
 |
|
อยากถามปัญหาการ insert into อะครับ ผมจะทำให้มันเหมือนระบบตะกร้าแต่มัน inser tnto error |
|
 |
|
|
 |
 |
|
อันนี้หน้าแรกครับ
Code (PHP)
<html><head><title>00</title></head><body>
<?
$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
$objDB = mysql_select_db("db_medicine");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
$strSQL = "SELECT * FROM product";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="948" border="1">
<tr class="none">
<th width="27"> <div align="center" class="none">Id </div></th>
<th width="151"> <div align="center" class="none">Name </div></th>
<th width="70"> <div align="center">Number </div></th>
<th width="73"> <div align="center">Price </div></th>
<th width="64"> <div align="center">Edit </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td align="center" valign="top"><?=$objResult["id"];?></td>
<td align="left" valign="top"><?=$objResult["ProductName"];?></td>
<td align="center"><?=$objResult["Qty"];?></td>
<td align="center"><?=$objResult["Price"];?></td>
<td width="64" align="center"><a href="AddCart2.php?id=<?=$objResult["id"];?>">Add to Cart</a></td>
</tr>
<?
}
?>
</table>
<p>
<?
mysql_close($objConnect);
?></p><form id="form1" name="form1" method="post" action="add product.php">
<p>
<input type="submit" id="submit2" value="Add" name="submit2"
style="float:center;background:#3B59A8;
border:1px solid #000;color:#ffffff;font-weight:bold;"/>
</p>
</form> </p>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<script type="text/javascript">
var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>

หน้าที่ 2 ครับ
Code (PHP)
<html><head><title>77</title></head><body>
<?
$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
$objDB = mysql_select_db("db_medicine");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
$strSQL = "SELECT * FROM product WHERE id = '".$_GET["id"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found id=".$_GET["id"];
}
else
{
?>
<table width="827" border="1">
<tr class="สีเขียว">
<th width="35" align="center" valign="top"> <div align="center">Id </div></th>
<th width="175" align="left" valign="top"> <div align="center">Name </div></th>
<th width="70" align="center" valign="top"> <div align="center">Number </div></th>
<th width="82" align="center" valign="top"> <div align="center">Price </div></th>
</tr>
<tr>
<td width="35" align="center" valign="top"><div align="center">
<input type="text" name="txtid" size="5" value="<?=$objResult["id"];?>" />
</div></td>
<td width="175" align="left" valign="top"><input type="text" name="txtname" size="25" value="<?=$objResult["ProductName"];?>" /></td>
<td width="70" align="center" valign="top"><input type="text" name="txtnumber" size="10" value="<?=$objResult["Qty"];?>" /></td>
<td width="82" align="center" valign="top"><input type="text" name="txtprice" size="7" value="<?=$objResult["Price"];?>" /></td>
</tr>
</table>
<p>
<input type="submit" value="Submit" name="submit2"
style="float:center;background:#3B59A8;
border:1px solid #000;color:#ffffff;font-weight:bold;"/>
<?
}
mysql_close($objConnect);
?>
</p>
</form></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<script type="text/javascript">
var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>

หน้าสุดท้าย
Code (PHP)
<html><head><title>88</title></head><body>
<?
$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
$objDB = mysql_select_db("db_medicine");
$strSQL = "insert into cart2 SET ";
$strSQL .="id = '".$_POST["txtid"]."' ";
$strSQL .=",Qty = '".$_POST["txtnumber"]."' ";
$strSQL .=",Price = '".$_POST["txtprice"]."' ";
$strSQL .="WHERE id = '".$_GET["id"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";?><br><br>
<a href="total product.php">Back to Inventories Page</a> <?
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</p>
</form></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<script type="text/javascript">
var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>

ข้อมูลมันก็มานี่ครับแล้วทำไมมันเพิ่มไม่ได้อะครับ ผมจะทำให้มันเหมือนระบบตะกร้าสอนค้าอะครับแต่ให้เพิ่มทีละรายการ
Tag : PHP, MySQL, HTML/CSS, CakePHP

|
|
 |
 |
 |
 |
Date :
2011-09-23 21:04:50 |
By :
ronnachach |
View :
769 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รูปแบบ insert ผิดนะครับ ลองไปศึกษาว่าจะต้องใช้แบบไหน
|
 |
 |
 |
 |
Date :
2011-09-23 21:49:44 |
By :
onedan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง ดู sql เติม mysql_error()
echo "Error Save [".$strSQL.".mysql_error()]";
insert แบบนี้ ใช้ได้นะครับ ผมเคยใช้ ไม่ผิด แต่ไม่ค่อยใช้กันเยอะ
|
 |
 |
 |
 |
Date :
2011-09-24 23:33:48 |
By :
ckcr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมหมายถึง where นะ
|
 |
 |
 |
 |
Date :
2011-09-25 02:22:41 |
By :
onedan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ออ ลืมดูโทษที จ๊ะ
|
 |
 |
 |
 |
Date :
2011-09-25 12:07:16 |
By :
ckcr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|