我正在使用 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!";
最佳答案
首先连接到 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)
关于php - 使用 PHP 创建 html 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20484991/