网站建设资讯

NEWS

网站建设资讯

php处理html数据 php输出html源代码

怎么用php把html表单内容写入数据库

1:首先要使用PHP的超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data)

成都做网站、成都网站制作、成都外贸网站建设,成都做网站公司-创新互联已向上千多家企业提供了,网站设计,网站制作,网络营销等服务!设计与技术结合,多年网站推广经验,合理的价格为您打造企业品质网站。

2:然后使用INSERT INTO 语句用于向数据库表中插入新记录。

具体示例:

(1)首先创建了一个名为 "Persons" 的表,有三个列:"Firstname", "Lastname" 以及 "Age"。

?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 

VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 

VALUES ('Glenn', 'Quagmire', '33')");

mysql_close($con);

?

(2)其次创建一个 HTML 表单,这个表单可把新记录插入 "Persons" 表。

html

body

form action="insert.php" method="post"

Firstname: input type="text" name="firstname" /

Lastname: input type="text" name="lastname" /

Age: input type="text" name="age" /

input type="submit" /

/form

/body

/html

(3)接着当用户点击上例中 HTML 表单中的提交按钮时,表单数据被发送到 "insert.php"。"insert.php" 文件连接数据库,并通过

$_POST 变量从表单取回值。然后,mysql_query() 函数执行 INSERT INTO 语句,一条新的记录会添加到数据库表中。

?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("my_db", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)

VALUES

('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "1 record added";

mysql_close($con)

?

PHP中如何调用html?

html表单最基本的形式是form中设置action属性(数据提交路径)method表示提交数据的类型(get和post)。使用这种方式提交表单,表单元素必须设置name属性。

表单中设置这两个属性就可以获得表单的值了。

例如:

form action="index.php" method="post"

input type="text" name="user" /

input type="submit" value="提交" /

/form

?php

//post接收表单传过来的值

$user=$_POST['user'];

echo $user;

?

php如何结合html调用数据?

在html中调用php内容,可以用script src="friendlinks.php"/script然后在friendlinks.php中调取数据库数据。并输出适当的html,或者输出xml、json都可以,只是图简单的话,只要输出html就行了。

如何php写入HTML文件,然后php访问HTML文件的内容画面,怎么做?

PHP写入HTML文件可以使用file_put_contents,例如:

file_put_contents('a.html', "html

bodyhello/body

/html");

PHP访问HTML文件可以使用readfile、file等,例如:

readfile('a.html');


分享题目:php处理html数据 php输出html源代码
浏览路径:http://cdweb.net/article/dodgehi.html