php 实现简单的注册页面 并把注册信息插入到 mysql 数据库中

php 实现简单的注册页面 并把注册信息插入到 mysql 数据库中,第1张

注册页面:reghtml

<form action="regphp" method="POST">

<table>

<tr><td>用户名:</td><td><input type="username" size="20"></td></tr>

<tr><td>密码:</td><td><input type="userpass" size="20"></td></tr>

<tr><td>确认密码:</td><td><input type="ruserpass" size="20"></td></tr>

<tr><td>邮箱:</td><td><input type="email" size="50"></td></tr>

<tr><td>电话:</td><td><input type="telphone" size="20"></td></tr>

<tr><td><input type="Submit" value="注册"></td></tr>

</table>

</form>

接收页面:regphp

<%php

$db = mysql_connect("localhost", "root", "12345");

mysql_select_db("dataname", $db);

mysql_query("insert into tablename(username, userpass, email, telphone) values('$_POST[username]', '$_POST[userpass]', '$_POST[email]', '$_POST[telphone]')");

echo "注册成功";

%>

不要用insert,直接用记录集就行了给你一段

'添加记录

<%

set rs=servercreateobject("adodbrecordset")

sql="select user,qq,email,content,data from main"

rsopen sql,conn,1,3

rsaddnew

user=requestform("user")

qq=requestform("qq")

email=requestform("email")

content=requestform("content")

rs("user")=user

rs("qq")=qq

rs("email")=email

rs("content")=content

rsupdate

rsclose

set rs=nothing

connclose

set rs=nothing

%>

这种东西用SSH作吧,由struts将截获的请求分发到相关的action进行处理hibernate做数据库的CRUD最好把hibernate交给spring管理,如果需要进行插入数据的话用servlet简单点,如果功能比较多需要进行业务逻辑处理的最好还是用框架

以下是简单示例:

<html>

<head>

<title>注册示例</title>

</head>

<body>

<form method='post' action='testphp'>

<table bgcolor='#cccccc'>

<tr>

<td>Email address:</td>

<td><input type='text' name='email' size=30 maxlength=100></td></tr>

<tr>

<td>Preferred username <br />(max 16 chars):</td>

<td valign='top'><input type='text' name='username'

size=16 maxlength=16></td></tr>

<tr>

<td>Password <br />(between 6 and 16 chars):</td>

<td valign='top'><input type='password' name='passwd'

size=16 maxlength=16></td></tr>

<tr>

<td>Confirm password:</td>

<td><input type='password' name='passwd2' size=16 maxlength=16></td></tr>

<tr>

<td colspan=2 align='center'>

<input type='submit' value='Register'></td></tr>

</table></form>

<php

//连接数据库

function db_connect()

{

$result = new mysqli('localhost', 'test', 'password', 'test');

if (!$result)

return false;

return $result;

}

//注册用户资料到数据库

function register($username, $email, $password)

{

// connect to db

$conn = db_connect();

//检查用户名是否唯一

$result = $conn->query("select from user where username='$username'");

if (!$result)

throw new Exception('无法搜索数据库');

if ($result->num_rows>0)

throw new Exception('该用户名已经存在,请检查后重试!');

// 如果通过,则写入数据库

$result = $conn->query("insert into user values

('$username', sha1('$password'), '$email')");

if (!$result)

throw new Exception('无法写入数据库,请稍候重试');

return true;

}

$email=$_POST['email'];

$username=$_POST['username'];

$passwd=$_POST['passwd'];

$passwd2=$_POST['passwd2'];

register($username, $email, $passwd);

>

</body>

</html>

以上就是关于php 实现简单的注册页面 并把注册信息插入到 mysql 数据库中全部的内容,包括:php 实现简单的注册页面 并把注册信息插入到 mysql 数据库中、ASP制作的简单会员注册页面,要求注册信息输入后点提交即提交到数据库。 运行时提示INSERT INTO语句错误、做了一个简单的注册页面,有用户名,密码,希望点击提交按钮将注册信息提交到mysql数据库,求相应java代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9294856.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存