2013-12-10 123 views
0

我正在使用PHP創建HTML表格。我創建了我的數據庫和表,但無法弄清楚如何實際創建表。有一個斷開,我在某處失蹤,有人可以幫我嗎?我將如何轉換成用於創建HTML數據庫代碼/表使用PHP創建html表格

create database testproject 
use testproject 
create table caller_info (caller_id int(11) unsigned auto_increment primary key not null, 
first_name varchar(35) not null, Last_name varchar(35) not null, franchise varchar(25) not 
null) 

create table caller_call_record(call_record_id int(11) not null, Call_Description varchar(50), 
franchise_id int(10) not null, email varchar(40) not null, username varchar(25) primary key not 
null); 

create table caller_escalation 
(
call_escalation_id int(11) unsigned auto_increment not null, 
Second_Level varchar(5) not null, 
caller_id int(11) unsigned not null, 
PRIMARY KEY(call_escalation_id), 
username varchar(25) not null, 
FOREIGN KEY(caller_id) 
REFERENCES caller_info(caller_id), 
FOREIGN KEY (username) REFERENCES caller_call_record (username) 
); 

我還創建了一個delete功能和update功能,但就像我說的,我失去了對如何實際創建該表? 這裏是刪除功能,我想表明我已經完成了這項工作,但真的需要幫助把它放在一起。

<html> 
<title>Delete Call Log entry</title> 
<style type="text/css" > 

</style> 

</head> 

<body> 

Franchise ID First Name Last Name Email Address </br><table border="3"> 

</table> 

<h2>Delete Franchise Call Log</h2> 
<form method="post" action="caller_info_test.php"> 


Enter Franchise ID record to delete <br /> 
<input type="text" name="franchise id" size="30" /><br /> 

<input type ="submit" value="Delete Call Log" name="submit" /> 

</form> 

</body> 
</html> 

這裏是我的更新功能

<html> 
<title>Franchise Calls</title> 
</head> 

<body> 

<h2>Franchise Call Log </h2> 
<form method="post" action="caller_info_test.php"> 

First Name : <br /> 
<input type="text" name="first_name" size="30" /><br /> 

Last Name : <br /> 
<input type="text" name="last_name" size="40" /><br /> 

<input type ="submit" value=" Update Record" name="submit" /> 

</form> 

</body> 
</html> 

這裏是我的三個表創建的PHP:

<?php 
//connect to the database - and create the caller_info table 
include("inc_connect_local.php"); 
echo "Connected to mysql"; 

//Open the testproject database 

mysql_select_db("testproject"); 
//create "caller_call_record" table 
$query = "CREATE TABLE caller_call_record(
call_record_id int(11) not null, 
Call_Description varchar(50), 
franchise_id int(10) not null, 
Email varchar(40) not null, 
Username varchar(25) primary key not null) 
"; 

echo "Table created successfully."; 
?> 

<?php 
//connect to the database - and create the caller_info table 
include("inc_connect_local.php"); 
echo "Connected to mysql"; 

//Open the testproject database 

mysql_select_db("testproject"); 
//create "caller_call_record" table 
$query = "CREATE TABLE caller_call_record(
call_record_id int(11) not null, 
Call_Description varchar(50), 
franchise_id int(10) not null, 
Email varchar(40) not null, 
Username varchar(25) primary key not null) 
"; 

echo "Table created successfully."; 
?> 

<?php 
//connect to the database - and create the caller_info table 
include("inc_connect_local.php"); 
echo "Connected to mysql"; 

//Open the testproject database 

mysql_select_db("testproject"); 
//create "caller_escalation" table 
$query = "CREATE TABLE caller_escalation (
call_escalation_id int(11) unsigned auto_increment not null, 
Second_Level varchar(5) not null, 
caller_id int(11) unsigned not null, 
PRIMARY KEY(call_escalation_id), 
username varchar(25) not null, 
FOREIGN KEY(caller_id) 
REFERENCES caller_info(caller_id), 
FOREIGN KEY (username) REFERENCES caller_call_record (username) 
)"; 
mysql_query($query); 

echo "Table created successfully."; 
echo "Franchise Call Log Database successfully created!"; 
+0

你有HTML,現在你需要的PHP。你有嘗試過什麼嗎? –

+0

一旦在數據庫中獲得了數據,就可以用select語句提取它並將其呈現給用戶。但是,您將需要一些PHP來做到這一點,這是我在這裏沒有看到的。 – Zarathuztra

+3

你會需要一點[教程](http://tutorial.world.edu/web-development/create-php-insert-select-update-delete-mysql-database-table/「PHP插入,選擇,更新,在MySQL數據庫表中刪除「)。 – mdesdev

回答

0

首先連接到root帳戶或其他用戶的所有特權。請致電查詢此字符串

CREATE DATABASE IF NOT EXISTS `YourNameHere` 

下一頁創建表

CREATE TABLE `YourDatabaseName`.`YourTableName` (`value` char(1) NOT NULL, `OtherValue` varchar(40) NOT NULL, `ThirdValue` varchar(40) NOT NULL, `FourthValue` varchar(50) NOT NULL) 

如果您選擇使用mysql_select_db那麼該命令將

CREATE TABLE `YourTableName` (`value` char(1) NOT NULL, `OtherValue` varchar(40) NOT NULL, `ThirdValue` varchar(40) NOT NULL, `FourthValue` varchar(50) NOT NULL)