我使用php创建了注册表单。
我想在新窗口中显示当前注册的用户详细信息。
这是我的data.php:
<?php
include('config.php');
$result = $db->prepare("SELECT * FROM crop ORDER BY id DESC");
$result->execute();
while( $row = $result->fetch()){
$fname = $row['fname'];
$lname = $row['lname'];
$email = $row['email'];
$pass = $row['pass'];
$phone = $row['phone'];
$sex_select = $row['sex_select'];
$month = $row['month'];
$day = $row['day'];
$year = $row['year'];
$id = $row['id'];
}
?>
<html>
<body>
<from >
<table style="color:purple;border-style:groove; height:150px;width:350px" background="3.jpg">
<tr>
<td style="font-family:Copperplate Gothic Bold"> </td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Id no:</td>
<td class="auto-style4">
<input id="Text1" type="text" value='<?php echo $id; ?>'/></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">FirstName:</td>
<td class="auto-style4">
<input id="Text2" type="text" value='<?php echo $fname; ?>'/></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">LastName:</td>
<td class="auto-style4">
<input id="Text3" type="text" value='<?php echo $lname; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Email:</td>
<td class="auto-style4">
<input id="Text4" type="text" value='<?php echo $email; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Password:</td>
<td class="auto-style4">
<input id="Text5" type="text" value='<?php echo $pass; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Contact Number:</td>
<td class="auto-style4">
<input id="Text6" type="text" value='<?php echo $phone; ?>' ></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Sex_Select:</td>
<td class="auto-style4">
<input id="Text7" type="text" value='<?php echo $sex_select; ?>'/></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Month:</td>
<td class="auto-style4">
<input id="Text8" type="text" value='<?php echo $month; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Day:</td>
<td class="auto-style4">
<input id="Text9" type="text" value='<?php echo $day; ?>'/></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Year:</td>
<td class="auto-style4">
<input id="Text10" type="text" value='<?php echo $year; ?>'/></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
</body>
</html>
我在index.php中包含了data.php文件。
现在显示,http://s28.postimg.org/ndbnjlyz1/Untitled_1_copy.png
任何人都可以帮助我。提前谢谢。
答案 0 :(得分:0)
这可以在您插入数据库的那一刻完成
//use
session_start(); //then
$v1="'" . $conn->real_escape_string('col1_value') . "'";
$sql="INSERT INTO tbl (col1_varchar, col2_number) VALUES ($v1,10)";
if($conn->query($sql) === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
}
else {
$_SESSION['user_id'] = $conn->insert_id; //get the id in a session variable
}
//redirect to another page say user_details.php and show the result using the session...
header("location:user_details.php");
在查询中进行编辑
$result = $db->prepare("SELECT * FROM crop
WHERE id = ".$_SESSION['user_id']."
ORDER BY id DESC"); //this brings the data of the last entered user.