|
 |
|
สอบถามเกี่ยวกับการ INSERT ข้อมูลเข้าฐานข้อมูลค่ะ ทำแล้วไม่ได้อย่างที่ต้องการเลยค่ะ |
|
 |
|
|
 |
 |
|
สอบถามเกี่ยวกับการ INSERT ข้อมูลเข้าฐานข้อมูลค่ะ ทำแล้วไม่ได้อย่างที่ต้องการเลยค่ะ
Code (PHP)
$query = sprintf("INSERT INTO products (product, price,link)
VALUES( '%s', '%s','%s')",
mysql_real_escape_string($product_name),
mysql_real_escape_string($product_price),
mysql_real_escape_string($id_product));
จากโค๊ดด้านบนนะคะ หลังจากทดสอบโค๊ดแล้ว หนูก็ได้ข้อมูลในฐานข้อมูล table products ตามนี้คะ
คอลัมน์ product มีค่าเป็น item1
คอลัมน์ price มีค่าเป็น 20
คอลัมน์ link มีค่าเป็น 12
หลังจากนั้นหนูก็ทำการเขียนโค๊ดเพิ่มเติมค่ะ โดยหนูต้องการเพิ่มค่าที่จะ INSERT เข้าคอลัมน์ link น่ะคะ โดยต้องการให้คอลัมน์ link มีค่าเป็น item1-12.html คะ
หนูจึงเขียนโค๊ดใหม่ได้ดังนี้ค่ะ
Code (PHP)
$query = sprintf("INSERT INTO products (product, price,link)
VALUES( '%s', '%s','%s')",
mysql_real_escape_string($product_name),
mysql_real_escape_string($product_price),
mysql_real_escape_string($product_name-$id_product.html));
แต่ก็ไม่ได้อย่างที่ต้องการค่ะ ไม่ทราบว่าจะต้องเขียนโค๊ดอย่างไรค๊ะ แนะนำด้วยนะค๊ะ ^_^
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2012-08-27 22:40:25
|
 |
 |
 |
 |
Date :
2012-08-27 22:39:03 |
By :
dferru |
View :
920 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
item1-12.html หมายความว่าอย่างไรครับ ? PHP แสดง Error อะไรออกมาบ้างครับ ?
|
 |
 |
 |
 |
Date :
2012-08-28 00:42:36 |
By :
kathikan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะเป็นการสร้าง url ไปใส่ในฐานข้อมูลหรือเปล่าครับ
แบบว่าต้องการให้คอลัมน์ link มีค่้าเป็น mysql_real_escape_string($product_name-$id_product.html));
แต่ผมว่าที่มันไม่ออก น่าจะเป็นเพราะว่า synex ผิดหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-08-28 09:10:45 |
By :
peap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|