我正在使用PHP创建HTML表。我已经创建了我的数据库和表,但无法弄清楚如何实际创建表。我在某个地方失踪了,有人可以帮助我吗?我如何将其转换为用于创建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 :(得分: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)