20分 php新手求 网页自动跳转

php编程的问题:
想要做一个在线申请的功能,简单概括如下:
application.php--填表申请,有一些input和submit按钮,在input全部输入之前,submit按钮是置灰的,待全部输入完成后,才可用。
view.php--点击submit后,显示用户输入的内容
比如有一个函数教check(),用来检查input是否合法,再有一个函数叫insert(),用于添加数据库,
我知道用form action=“view.php”可以跳转到view.php,但是问题是,check和insert应该写在那里,如果些在view.php里,需要action="application.php"怎样跳转到view.php。如果写在view.php里是不是check和insert感觉也不太好。如果单独新建一个文件,只写这两个函数,怎样自动跳转到view.php?
多谢,最好有代码,谢谢

首先,作为新手,你的想法还是很不错的,值得肯定!呵呵
不过,刚开始学php,建议你不要一下子就试图掌握太多东西,要从易到难,而且要注重去理解php的思想,尽量去掌握原理性的东西。比如,你说的这一点“在input全部输入之前,submit按钮是置灰的,待全部输入完成后,才可用”,我觉得可以暂时先不要考虑。当然如果你想现在就来掌握这一点,建议你要多看点ajax的资料,或者多了解一点javascript(js)。你明白了它们的原理,对php又挺熟了的话,要实现你说的这个并不是难事,有好几种解决办法。当然,可能实现的时候跟你所想的会有一点偏差。但是建议你现在先不要去想着要实现它,循序渐进,这样你才不会把各种语言、技术思想混淆,导致你理解上的偏差。基于此,我这里给你一个稍微简单一点的实现方法,你可以参考着来弄。
view.php--------
<?
include_once("db_connection.php");
$db->debug=0;
if($_POST)
{
$row = $_POST;
$dbField["Name"] = $row["UserName"];
$dbField["Password"] = $row["Password"];
$db->AutoExecute("users",$dbField,"INSERT");
$UserID=$db->Insert_ID();
echo"<script language='javascript'>";
echo"location='application.php?UserID=$UserID'";
echo"</script>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE TYPE="text/css">
.dataLabel {
font-size:14px;
font-family:sans-serif ;
}
.dataField {
font-size:12px;
font-family:sans-serif ;
}
body {
margin-left: 0px;
margin-top: 200px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #E5E5E5;
}
.Button
{
border-right: #737357 1px solid;
border-top: #737357 1px solid;
border-left: #737357 1px solid;
color: #3b3b1f;
border-bottom: #737357 1px solid;
background-color: #eeeeee;
}
</STYLE>
</head>

<body>
<form action="" method="post" name="pwcheck" id="pwcheck">
<table cellpadding="0" cellspacing="2" border="0" align="center">
<tr>
<td align="left" class="dataLabel"><b>user name:</b></td>
<td class="dataField"><input id="UserName" name="UserName" type="text" size="20" value="<?=$row["UserName"]?>"></td>
</tr>
<tr>
<td align="left" class="dataLabel"><b>password:</b></td>
<td class="dataField">
<input id="Password" name="Password" type="text" size="20" value="<?=$row["Password"]?>">
</td>
</tr>
<tr>
<td colspan="2" align="center"><input name="confirm" id="confirm" type="submit" class="Button" value=" Confirm " size="40" onClick="return CheckInfo();"></td>
</tr>
</table>
</form>
</body>
</html>
<script>
function CheckInfo(){
var UserName = document.getElementById("UserName").value;
var Password = document.getElementById("Password").value;
if(UserName == "" || Password == ""){
alert("Please input name and password!");
return false;
}else{
return true;
}
}
</script>
application.php----------
<?
include_once("db_connection.php");
$db->debug=0;
//下面是去数据库里边选相应的信息。
$UserInfo = $db->GetRow("select * from users where ID='$UserID'");
//下面的代码是显示,你可以不要这样显示,可以弄到页面body里边去显示,比如显示在text里边等等。
echo "Your name is ".$UserInfo[Name]."<br />";
echo "Your Password is ".$UserInfo[Password]."<br />";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Gforge-log on</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE TYPE="text/css">
body {
background-color: #E5E5E5;
}
</STYLE>
</body>
</html>
···································
说明,我里边的include_once("db_connection.php");这个是对于数据库操作的一个功能实现模块,你自己去写的时候,由于你没有这个东西,所以数据库连接的部分要自己写一下,不过你看我给你的代码应该看得出来是在做什么事情。
这两个页面都是我随便写了一下,具体你要什么布局,怎么显示信息,你要自己去调整一下。
奇怪,怎么修复不了答案了。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-10-29
1. 楼上的老兄关于学习方法的话很赞~~

2. check()检查输入是否合法的过程称作“验证”(verification),如果不是逻辑特别复杂或者需要数据库支持的话通常用客户端脚本来实现(如Javascript),因为更容易和直观。

用PHP也可以,可以写在application.php里,表单就提交给application.php(form action = "application.php")。

application.php完成验证之后要显示view.php的内容,这可以通过include("view.php")把view.php嵌到application.php里显示,也可以用header('Location: view.php'),但用这种方法注意这之前不能有任何HTML输出
第2个回答  2008-10-30
<?php
echo("<script language='javascript'>");
echo("alert(\"对不起,你没有权限,请先登录\");");
echo("location.href=\"index.php\";");
echo("</script>");
?>

这样的东西??
要是的话自己改
第3个回答  2008-11-05
楼上说的挺清楚的,我在这里做个补充:
application.php

From中设置action=“view.php”,提交按钮中加入onClick="return Check();",并在本页中用JS写个判断函数,大概如下:

<script language="JavaScript">
<!--
function Check()
{
if(isNull(document.Reg_form.UserCode.value)) {
document.Reg_form.UserCode.focus();
alert("请输入您要注册的动伴账号!");
return false;
}
……//其他的判断代码
}
/*判断是否为空*/
function isNull(str){
var returnValue = true;
if((typeof(str) != "undefined") && (str != "") && (str != null)){
returnValue = false;
}
return returnValue;
}
//-->
</script>
这样在提交时,就会执行Check()函数,检查通过时,会将数据提交到view.php页面

view.php
在本页先将上页中提交的数据,显示出来,加入按钮来让用户单击后进行保存,此时form action=“view.php”,并在页面开始时判断后调用insert()进行保存。
insert()函数代码如四楼所写即可,引用如下:
<?
include_once("db_connection.php");
$db->debug=0;
if($_POST)
{
$row = $_POST;
$dbField["Name"] = $row["UserName"];
$dbField["Password"] = $row["Password"];
$db->AutoExecute("users",$dbField,"INSERT");
$UserID=$db->Insert_ID();
echo"<script language='javascript'>";
echo"location='application.php?UserID=$UserID'";
echo"</script>";
}
?>

这里要注意的,Check()函数是用JS写的,并在将数据提交前进行判断。
而Insert()函数是用PHP写的,只是方便重复调用!
写的有点简单,希望能帮到你,谢谢。
第4个回答  2008-10-31
ajax可以实现 关键是注意流程分析

参考资料:

第5个回答  2008-10-28
javascript也可以实现

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网