|
|
|
สอบถาม Insert 2 ตาราง pk ไม่เข้า fk หน่อยค่ะ (มีรูป) |
|
|
|
|
|
|
|
ตามรูปเลยค่ะ
พอดีสร้าง form insert 2 ตาราง โดย ฝั่งซ้าย มี Address_ID เป็น pk และฝั่งขวา Store_ID เป็น pk , Address_ID เป็น fk
กรอกข้อมูลแล้ว pk Address_ID ไม่เข้า fk Address_ID
Code (PHP)
<html>
<head>
<title>Informatica_check</title>
<meta charset="UTF-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head><br>
<?php
mysql_connect("localhost", "root", "1234") or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_query('SET CHARACTER SET utf8');
mysql_query('SET NAMES utf8');
mysql_select_db(etd) or die("เลือกฐานข้อมูลไม่ได้");
$strSQL1 = "INSERT INTO store (Storename,Adminname,Tel,Email,Detail) VALUES ('" . $_POST["txtStorename"] . "',"
. " '" . $_POST["txtAdminname"] . "','" . $_POST["txtTel"] . "','" . $_POST["txtEmail"] . "','" . $_POST["txtDetail"] . "')";
$objQuery = mysql_query($strSQL1);
$strSQL2 = "INSERT INTO address (Number,Moo,Village,Layer,Alley,Street,Amphur,District,Province,Code) "
. "VALUES ('" . $_POST["txtNumber"] . "','" . $_POST["txtMoo"] . "','" . $_POST["txtVillage"] . "',"
. "'" . $_POST["txtLayer"] . "','" . $_POST["txtAlley"] . "','" . $_POST["txtStreet"] . "',"
. "'" . $_POST["txtAmphur"] . "','" . $_POST["txtDistrict"] . "','" . $_POST["txtProvince"] . "',"
. "'" . $_POST["txtCode"] . "')";
$objQuery = mysql_query($strSQL2);
mysql_close($conn);
?>
<script language=Javascript>top.location.href = "finish.php";</script>
</html>
Tag : PHP, HTML/CSS
|
ประวัติการแก้ไข 2015-02-15 00:37:13
|
|
|
|
|
Date :
2015-02-15 00:36:16 |
By :
koyung |
View :
1615 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$strSQL1 = "INSERT INTO address (Number,Moo,Village,Layer,Alley,Street,Amphur,District,Province,Code) "
. "VALUES ('" . $_POST["txtNumber"] . "','" . $_POST["txtMoo"] . "','" . $_POST["txtVillage"] . "',"
. "'" . $_POST["txtLayer"] . "','" . $_POST["txtAlley"] . "','" . $_POST["txtStreet"] . "',"
. "'" . $_POST["txtAmphur"] . "','" . $_POST["txtDistrict"] . "','" . $_POST["txtProvince"] . "',"
. "'" . $_POST["txtCode"] . "')";
$objQuery = mysql_query($strSQL1);
$Address_ID = mysql_insert_id();
$strSQL2 = "INSERT INTO store (Storename,Adminname,Tel,Email,Detail,Address_ID) VALUES ('" . $_POST["txtStorename"] . "',"
. " '" . $_POST["txtAdminname"] . "','" . $_POST["txtTel"] . "','" . $_POST["txtEmail"] . "','" . $_POST["txtDetail"] . "','" . $Address_ID . "')";
$objQuery = mysql_query($strSQL2);
mysql_close($conn);
|
|
|
|
|
Date :
2015-02-15 03:08:15 |
By :
sabaitip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|