|
 |
|
สอบถามเรื่องการ insert into ซ้ำๆกัน ลงในฐานข้อมูล ผมทำแล้วมันขึ้นแค่บรรทัดเดียวครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>SAVE DATA</title>
</head>
<body>
<center>
<?
if($_FILES["fileup"]["name"] != "")
{
$fp = fopen($_FILES["fileup"]["tmp_name"],"r");
$ReadBinary = fread($fp,filesize($_FILES["fileup"]["tmp_name"]));
fclose($fp);
$FileData = addslashes($ReadBinary);
}
$objConnect = mysql_connect("localhost","root","12345") or die("ติดต่อฐานข้อมูลไม่ได้");
$objDB = mysql_select_db("rlb");
$strSQL = "INSERT INTO dt ";
$strSQL .="(Name, Size, Deep, Amount, Iron, DB, SD, RB, Ad, Leng, Bra, Pha, Con, Cal,images) ";
$strSQL .="VALUES";
$strSQL .="('".$_POST["txtname"]."','".$_POST["txtsize"]."'";
$strSQL .=",'".$_POST["txtdeep"]."',".$_POST["txtamount"].",".$_POST["txtiron"]."";
$strSQL .=",".$_POST["txtdb"].",".$_POST["txtsd"].",".$_POST["txtrb"]."";
$strSQL .=",".$_POST["txtadd"].",'".$_POST["txtleng"]."','".$_POST["txtbra"]."'";
$strSQL .=",'".$_POST["txtpha"]."',".$_POST["txtcon"].",'".$_POST["txtcall"]."','".$FileData."')";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "บันทึกข้อมูล เรียบร้อย";
}
else
{
echo "Error Save [".$strSQL."]";
}
for($i = 1;$i <= 10;$i++)
{
$strSQL2 = "INSERT INTO work ";
$strSQL2 .="(ID) ";
$strSQL2 .="VALUES";
$strSQL2 .="('".mysql_insert_ID()."')";
$objQuery2 = mysql_query($strSQL2);
}
mysql_close($objConnect);
?>
<form name="form2"action="adminpage.php">
<input type="submit" name="btsubmit" value="กลับสู่หน้าแรก">
</form>
</center>
</body>
</html>
ตรงส่วนนี้
Code (PHP)
for($i = 1;$i <= 10;$i++)
{
$strSQL2 = "INSERT INTO work ";
$strSQL2 .="(ID) ";
$strSQL2 .="VALUES";
$strSQL2 .="('".mysql_insert_ID()."')";
$objQuery2 = mysql_query($strSQL2);
}
ผมอยากให้มัน เพิ่มลงในตาราง work 10 แถว แต่มันเพิ่มแค่บรรทัดเดียวครับ
ผมมือใหม่ครับ
Tag : PHP

|
ประวัติการแก้ไข 2011-09-05 11:28:42
|
 |
 |
 |
 |
Date :
2011-09-05 11:26:24 |
By :
kingwespo |
View :
917 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณตรวจสอบ Loop ให้ดีครับ และอีกอย่าง mysql_insert_id() ควรเก็บลงในตัวแปรก่อนน่ะครับ แล้วค่อยเอามาใช้
|
 |
 |
 |
 |
Date :
2011-09-05 14:01:39 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|