|
|
|
จะ Insert ข้อมมูลลง DB จากฟอร์มเดียว ลง 3 ตารางอ่ะคับ ต้องทำประมาณไหนบ้างครับ |
|
|
|
|
|
|
|
Relation ship model เป็นแบบไหนครับ ?
ผมลองออกแบบตัวอย่างให้นะ
tb_member
id_member (int 5 auto_increment)PK
name (varchar 255)
tb_program
id_program (int 5 auto_increment)PK
program (varchar 255)
tb_bill
id_bill (int 5 auto_increment)PK
id_member (int 5)FK
id_program (int 5)FK
***********************************************************************
Code (PHP)
<?php
mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db('yourdatabases') or die (mysql_error());
if($_POST['tMode'] == 'insert'){
$sql = " INSERT INTO tb_bill (id_member, id_program) ";
$sql.= " VALUES ";
$sql.= " ('".$_POST['id_memeber']."', '".$_POST['id_program']."') ";
$qr_sql = mysql_query($sql) or die (mysql_error());
if($qr_sql){
echo 'Save is done !!! ';
}else{
echo 'Command error : '.$qr_sql;
}
}
?>
<form name='Myfrm' action='' method='POST'>
<label>Member : </label>
<select name="id_member">
<option value='0'></option>
<?php
$sel = " SELECT id_member, name FROM tb_member ";
$qr = mysql_query($sql) or die (mysql_error());
while($fetch = mysql_fetch_assoc($qr)){
echo "<option value=\"".$fetch['id_member']."\">".$fetch['name']."</option> ";
}
?>
</select>
<label>Program : </label>
<select name="id_program">
<option value='0'></option>
<?php
$sel1 = " SELECT id_program, program FROM tb_program ";
$qr1 = mysql_query($sql1) or die (mysql_error());
while($fetch1 = mysql_fetch_assoc($qr1)){
echo "<option value=\"".$fetch1['id_program']."\">".$fetch1['program']."</option> ";
}
?>
</select>
<input type='hidden' name='tMode' value='insert' />
<input type='submit' name='submit' value='Save' />
</form>
|
|
|
|
|
Date :
2012-12-25 10:51:23 |
By :
popnakub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับจะลองไปปรับใช้ครับ
|
|
|
|
|
Date :
2012-12-25 11:09:55 |
By :
th3tee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|