一、页面表单提交到另一页面
fixed php
<html>
<head><title>Workflow System</title></head>
<body>
<h1>Register for an Account:</h1>
<form action="registration_action.php" method="POST">
Username: <input type="text" name="name" /><br />
Email: <input type="text" name="email" /><br />
Password: <input type="password" name="pword[]" /><br />
Password (again): <input type="password" name="pword[]" /><br />
<input type="submit" value="GO" />
</form>
</body>
</html>
registration_action.php
<html>
<body>
<p>You entered:</p>
<?php
//$username = $_POST['name'];
//$password = $_POST['pword'];
//echo "<p>Username = " . $username . "</p>";
//echo "<p>Password[1] = " . $password[0] . "</p>";
//echo "<p>Password[2] = " . $password[1] . "</p>";
function validate($allSubmitted){
$message = "";
$passwords = $allSubmitted['pword'];
$firstPass = $password[0];
$secondPass = $password[1];
$username = $allSubmitted['name'];
echo "<p>Username = " . $username . "</p>";
echo "<p>Password[1] = " . $firstPass . "</p>";
echo "<p>Password[2] = " . $secondPass . "</p>";
if ($firstPass != $secondPass) {
$message = $message."Passwords don't match<br />";
}
if (strlen($username) < 5 || strlen($username) > 50){
$message = $message."Username must be between 5 and 50 characters<br />";
}
if ($message == ""){
$message = "OK";
}
return $message;
}
if (validate($_POST) == "OK") {
echo "<p>Thank you for registering!</p>";
} else {
echo "<p>There was a problem with your registration:</p>";
echo validate($_POST);
echo "<p>Please try again.</p>";
}
?>
</body>
</html>
在registration_action.php当中
$firstPass = $password[0];$secondPass = $password[1]; 没有找到数据;
fixed.php
二、页面表单录入数据库
该表单也是和上面的fixed.php中差不多,多出部分是della表单中的元素;
login.php
1
<html>
2<head><title>Workflow System</title></head>
3<body>
4<h1>Register for an Account:</h1>
5<form action="registration_action.php" method="POST">
6
7name: <input type="text" name="name" /><br />
8ID: <input type="text" name="id" /><br />
9Password: <input type="password" name="pword[]" /><br />
10Password (again): <input type="password" name="pword[]" /><br />
11msn: <input type="text" name="msn" /><br />
12address: <input type="text" name="address" /><br />
13intruduction: <input type="text" name="intruduction" /><br />
14school: <input type="text" name="school" /><br />
15birthday: <input type="text" name="birthday" /><br />
16<input type="submit" value="GO" />
17</form>
18
19</body>
20</html>
21
22
registration_action2.php
1<html>
2<body>
3 <p>You entered:</p>
4
5<?php
6 $username = $_POST['name'];
7 $password = $_POST['pword'];
8 $id = $_POST['id'];
9 $birthday = $_POST['birthday'];
10 $msn = $_POST['msn'];
11 $address = $_POST['address'];
12 $intruduction = $_POST['intruduction'];
13 $school = $_POST['school'];
14
15 echo "<p>Username = " . $username . "</p>";
16 echo "<p>Password[1] = " . $password[0] . "</p>";
17 echo "<p>Password[2] = " . $password[1] . "</p>";
18 echo "<p>ID= " . $id . "</p>";
19 echo "<p>birthday = " . $birthday . "</p>";
20 echo "<p>msn = " . $msn . "</p>";
21 echo "<p>address = " . $address . "</p>";
22 echo "<p>intruduction = " . $intruduction . "</p>";
23 echo "<p>school = " . $school . "</p>";
24
25
26
27function db_connect($user='root',
28 $password='zdndd', $db='shop'){
29
30 mysql_connect('localhost', $user, $password)
31 or die('I cannot connect to db: ' . mysql_error());
32 mysql_select_db($db);
33
34}
35 db_connect();
36
37 $sql = "insert into della (name, address, school, id, birthday, msn, intruduction) values
38 ('".$username."', '".$address."', '".$school."', '".$id."', '".$birthday."', '".$msn."', '".$intruduction."')";
39 $result = mysql_query($sql);
40
41 if ($result){
42 echo "It's entered!";
43 } else {
44 echo "There's been a problem: ".mysql_error();
45 }
46?>
47</body>
48</html>
49 1.函数 db_connect 当中的$user='root',$password='zdndd', $db='shop' 都是我phpmyadmin中的用户名、密码、shop数据库;
2.$sql = "insert into della (name, address, school, id, birthday, msn, intruduction) values della是一个数据库表,本来这里不是della的,不写肯定是要报错的了,还要我够聪明看到了phpmyadmin当中的SQL语言,哇哈哈!搞定!
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com