|
![](/images/resource/spacer.gif) |
|
อยากทราบว่า ถ้าเรา คีย์ new table ใหม่เลยมีโค๊ด หรือ มี ตัวอย่างไหมครับ คล้ายๆๆ กับ insert into ข้อมูลลงใน Table แต่อันนี้เป็นการ คีย์ Table และฟิล ใหม่มาแล้ว insert ข้อมูลลงในฟิล PHP SQL |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ประมาณนี้หรือเปล่าครับ
Code (PHP)
$query = "SELECT ID FROM USERS";
$result = mysqli_query($dbConnection, $query);
if(empty($result)) {
$query = "CREATE TABLE USERS (
ID int(11) AUTO_INCREMENT,
EMAIL varchar(255) NOT NULL,
PASSWORD varchar(255) NOT NULL,
PERMISSION_LEVEL int,
APPLICATION_COMPLETED int,
APPLICATION_IN_PROGRESS int,
PRIMARY KEY (ID)
)";
$result = mysqli_query($dbConnection, $query);
//แล้วก็ตามด้วย การ Inert Into
//$query = "INSERT INTO USERS (EMAIL, PASSWORD, PERMISSION_LEVEL, APPLICATION_COMPLETED, //APPLICATION_IN_PROGRESS) VALUES ('[email protected]', 'fjsdfbsjkbgs', 0, 0, 0)";
//ค่าใน value ก็เปี่ลยนเป็นค่าที่รับมาจาก Form
$Email = $_POST["Email"];
$PASSWORD = $_POST["PASSWORD"];
$PERMISSION_LEVEL = $_POST["PERMISSION_LEVEL"];
$APPLICATION_COMPLETED = $_POST["APPLICATION_COMPLETED"];
$APPLICATION_IN_PROGRESS = $_POST["APPLICATION_IN_PROGRESS"];
$query2 = "INSERT INTO USERS (EMAIL, PASSWORD, PERMISSION_LEVEL, APPLICATION_COMPLETED, APPLICATION_IN_PROGRESS) VALUES ($Email, $PASSWORD, $PERMISSION_LEVEL, $APPLICATION_COMPLETED, $APPLICATION_IN_PROGRESS)";
$result2 = mysqli_query($dbConnection, $query2);
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2017-05-31 12:26:53 |
By :
ccjpn |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ผมยัง งง อ่ะครับ คือเหมือนเรา อยากเพิ่มวิชาใหม่ไป นะครับเป็น tableใหม่ ไม่ใช่ insert into table ที่มีอยู่แล้วอ่ะครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2017-05-31 12:47:29 |
By :
10154588533008947 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
code ด้านบน มันจะตรวจสอบดูว่ามี table นี้หรือยัง ถ้ายังไม่มีมันจะสร้างขึ้นมาใหม่ (CREATE TABLE ????) ในบรรทัดที่ 1-14 แต่ถ้ามี Table แล้วมันก็จะข้ามไป หลังจากนั้นจึงทำการ Insert ข้อมูลที่ post มาจาก Form
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2017-05-31 12:52:53 |
By :
ccjpn |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
รูปแบบ Form จะเป็นแบบไหนครับ โค๊ดในการ ก่อนทำการ insert ข้อมูลที่ Post มาจาก Form อ่ะครับ ขอดูตัวอย่างได้ไหมครับ จะขอบคุณมากๆๆครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2017-05-31 14:25:46 |
By :
10154588533008947 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 05
|