JS获得的值 var name=document.getElenmentById("username").value
用url 提交到后台 脚本 winodw.open('addname.php?username='+name)
后台获取前台提交的数据后用mysql命令写入数据库
<?php$username= $_GET['username']
$link=mysql_connect('127.0.0.1','root','******') or die("connection error".mysql_error())
$flag=mysql_select_db("testdb",$link)
mysql_query("set names "."utf8")
mysql_query('insert into user ( username) value ('.$username.')')
?>
使用cookie即可。
<!DOCTYPE HTML><html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="白菜编辑部">
<title>白菜编辑部</title>
<style type="text/css">
</style>
<script type="text/javascript">
function readCookie (name)
{
var cookieValue = ""
var search = name + "="
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf (search)
if (offset != -1)
{
offset += search.length
end = document.cookie.indexOf ("", offset)
if (end == -1)
end = document.cookie.length
cookieValue = unescape (document.cookie.substring (offset, end))
}
}
return cookieValue
}
function writeCookie (name, value, hours)
{
var expire = ""
if (hours != null)
{
expire = new Date ((new Date ()).getTime () + hours * 3600000)
expire = " expires=" + expire.toGMTString ()
}
document.cookie = name + "=" + escape (value) + expire
}
writeCookie ("myCookie", "my name", 24)
alert (readCookie ("myCookie"))
</script>
</head>
<body>
</body>
</html>
try{var dbc = new ActiveXObject("ADODB.Connection")
var dbcon = "Provider=Microsoft.Jet.OLEDB.4.0Data Source="+(location.href.replace(/file:[/]+([A-Z]:.*[/])([^/]+)/,"$1")).replace(/\%20/g," ")+"youData.mdb"
dbc.Open(dbcon)
return dbc
}
catch(e){ return alert("数据库连接出错")}
其他的就方便了,跟asp中一样
var rs = new ActiveXObject("ADODB.Recordset")
sql="select * from xxxx
rs.open(sql,conn,1,3)
rs.addnew
..
rs.update
rs.close
dbcon.close
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)