PHP100 2019-03-27
代码如下:
<form action="db.php" method="post"> <dl> <dt>UserName</dt><dd><input name="UserName" maxlength="20" type="text"/></dd> <dt>Password</dt><dd><input name="Password" maxlength="20" type="password"/></dd> <dt>Confirm Password</dt><dd><input name="ConfirmPassword" maxlength="20" type="password"/></dd> </dl> <input type="submit" name="ok" value="ok"/> </form>
代码如下:
<?php $match=true; if(isset($_POST["ok"])) { $pwd=$_POST["Password"]; $pwdConfirm=$_POST["ConfirmPassword"]; $match=($pwd==$pwdConfirm); $conn=new mysqli("localhost","root","123","UseCase"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query="insert into User(UserName,Password) values(?,?)"; $stmt=$conn->stmt_init(); $stmt->prepare($query); $stmt->bind_param('ss',$name,$pwd); $name=$_POST["UserName"]; $pwd=$_POST["Password"]; $stmt->execute(); if($stmt->errno==0) { $success=true; }else { $success=false; } $stmt->close(); $conn->close(); } ?>
代码如下:
<?php if(!$match) { ?> <p>Password and Confirm Password must match.</p> <?php } ?> <?php if(isset($success)) { if($success) { echo '<p>User Created Successfully!'; }elseif($sucess==false) { echo '<p>User Name existed.'; } } ?>
代码如下:
<table> <tr><th>User Name</th><th>CreateTime</th><th>Action</th> </tr> <?php include 'conn.php'; $query="select * from User;"; $res=$mysql->query($query); while($row=$res->fetch_array()) { ?> <tr> <td><?= $row['UserName'] ?></td> <td><?= date('Y-m-d',strtotime($row['CreateTime']))?> </td> <td><a href="UserEdit.php?action=update&ID=<?= $row['UserName'] ?>">Edit</a> <a href="action=delete&ID=<?= $row['UserName'] ?>">Delete</a> </td> </tr> <?php } $res->close(); $mysql->close(); ?> </table>
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh