IBM 学习php 第一部分
一、页面表单提交到另一页面
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
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>
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
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>
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
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![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
name: <input type="text" name="name" /><br />
8
ID: <input type="text" name="id" /><br />
9
Password: <input type="password" name="pword[]" /><br />
10
Password (again): <input type="password" name="pword[]" /><br />
11
msn: <input type="text" name="msn" /><br />
12
address: <input type="text" name="address" /><br />
13
intruduction: <input type="text" name="intruduction" /><br />
14
school: <input type="text" name="school" /><br />
15
birthday: <input type="text" name="birthday" /><br />
16
<input type="submit" value="GO" />
17
</form>
18![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
</body>
20
</html>
21![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
registration_action2.php
1
<html>
2
<body>
3
<p>You entered:</p>
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
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![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
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![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
27
function db_connect($user='root',
28
$password='zdndd', $db='shop'){
29![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
30
mysql_connect('localhost', $user, $password)
31
or die('I cannot connect to db: ' . mysql_error());
32
mysql_select_db($db);
33![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
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![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
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
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<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>
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<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中差不多,多出部分是della表单中的元素;
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
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语言,哇哈哈!搞定!