135-1821-9792

表单怎么跟mysql 表单与数据库连接

怎么把表单提交到mysql呢

具体方法操作如下:

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、网络空间、营销软件、网站建设、申扎网站维护、网站推广。

?php

$hostName = 'yourhost';

$userName = 'yourusername';

$passWords = 'yourpwd';

$conn = mysql_conn($hostName,$userName,$passWords);

if(!$conn){

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

}

$mysql_select_db('admin',$conn);

$sql="INSERT INTO user_zy (username, name, time,place,type,http,password)

VALUES

('$_POST[username]','$_POST[name]','$_POST[time]','$_POST[place]','$_POST[type]',

'$_POST[http]','$_POST[password]')";

mysql_query($sql,$conn); //这里是添加数据。

//读取数据

$sql = "select * form user_zy where 1"; //读取所有。

$sql = "select * form user_zy where id=".$id; //读取某一项。

$result = mysql_query($sql,$conn);

while($info = mysql_fetch_array($result)){

$arr[] = $info; //$arr 为最后所要读取的值。

}

可以用var_dump($arr)打印出来看看。

如何将JSP页面中的表单信息保存到Mysql数据库?

获取表单中的信息,然后插入到Mysql中 

%@ page language="java" contentType="text/html; charset=gbk"

pageEncoding="gbk"%

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""

%

int id = Integer.parseInt(request.getParameter("id"));

int rootid = Integer.parseInt(request.getParameter("rootid"));

%

html

head

meta http-equiv="Content-Type" content="text/html; charset=gbk"

titleReplay/title

/head

body

form method="post" action="ReplayOK.jsp"

input type="hidden" name="id" value="%=id %"

input type="hidden" name="rootid" value="%=rootid %"

table align="center"

tr

td

input type="text" name="title" size="80"

/td

/tr

tr

td

textarea cols="80" rows="20" name="cont"/textarea

/td

/tr

tr

td

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

/td

/tr

/table

/form

/body

/html

---------------------------------------------------------------

下面接收上面表单中传过来的信息,并插入到mysql中

%@ page language="java" contentType="text/html; charset=gbk"

pageEncoding="gbk"%

%@ page import="java.sql.*" %

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""

%

request.setCharacterEncoding("GBK");

int id = Integer.parseInt(request.getParameter("id"));

int rootid = Integer.parseInt(request.getParameter("rootid"));

String title = request.getParameter("title");

String cont = request.getParameter("cont").replaceAll("\n","br/");

Connection conn = null;

Statement st = null;

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection("jdbc:mysql://localhost/bbs?user=rootpassword=690115399");

st = conn.createStatement();

conn.setAutoCommit(false);

String sql = "insert into article values(null,?,?,?,?,now(),0)";

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setInt(1,id);

pstmt.setInt(2,rootid);

pstmt.setString(3,title);

pstmt.setString(4,cont);

pstmt.executeUpdate();

st.executeUpdate("update article set isleaf = 1 where id = " + id);

conn点抗 mit();

conn.setAutoCommit(true);

st.close();

pstmt.close();

conn.close();

%

html

head

meta http-equiv="Content-Type" content="text/html; charset=gbk"

titleInsert title here/title

/head

body

%response.sendRedirect("ShowArticleTree.jsp"); %

/body

/html

当然最好的方法还是应该用jsp + JavaBean方式。

html网站表单内容怎么提交到数据库?

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

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

具体示例:

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

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

(3)接着当用户点击上例中 HTML 表单中的提交按钮时,表单数据被发送到 "insert.php"。"insert.php" 文件连接数据库,并通过 $_POST 变量从表单取回值。然后,mysql_query() 函数执行 INSERT INTO 语句,一条新的记录会添加到数据库表中。


网站标题:表单怎么跟mysql 表单与数据库连接
转载源于:http://kswsj.com/article/ddissgi.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号