如何将id发布到另一个页面 [英] how to post id to another page
问题描述
嗨
我是新手,请帮我解决以下问题。单击更新按钮时,ID应该是另一个页面来处理更新功能。以下是我的全部代码
index.php
<?php
include_once ' ../。 ./inc/config.inc.php'跨度>;
$ sql = SELECT * FROM demo order by id;
尝试 {
$ result = mysqli_query($ con,$ sql);
包括' view.html.php';
}
catch (PDOException $ e)
{
echo $ e-> getMessage()。 \ n;
file_put_contents(' PDOErrors.txt',$ e-> getMessage(),FILE_APPEND );
// $ output ='从数据库中提取作者时出错!';
// 包含'../../ notification / errormsg.php';
退出();
}
view.html.php
< pre lang =PHP> < 脚本 语言 = javascript < span class =code-keyword>>
function change_action()
{
var frm_obj = document .getElementById( FRM跨度>);
frm_obj.action = data.php;
}
< / 脚本 >
< h3>用户详细信息< / h3 >
< form action = method = POST id = frm>
< table width = 100% align = center cellpadding = 4 cellspacing = 1>
< tr>
< td> ID < / td >
< td> ID < / td >
< td> NAME < / td >
< td> FIRST NAME < / / span> td >
< td> AGE < / td >
< td> < / td >
< / tr >
<?php
if (isset($ result)){
while ($ row = mysqli_fetch_array($ result)){?>
< tr>
< td>< input type = text name = vid value = <?php echo $ row ['id'];?> /> < / < span class =code-leadattribute> td >
< td><?php echo $ row [ id'];?> < / < span class =code-leadattribute> td >
< td><?php echo $ row [ name'];?> < / < span class =code-leadattribute> td >
< td><?php echo $ row [' firstname'];?> < / td >
< td><?php echo $ row [' age'];?> < / td >
< td>< input type = submit value = update name = update onclick = change_action()>
< input type = submit value = delete name = 删除 onclick = change_action()>
< / td >
< / tr >
<?php
}
}
mysqli_close($ con);
?>
< / table >
< / FORM >
<?php
包括' ../。 ./inc/footer.php';
data.php
<?php
include_once ' ../../ inc / config.inc.php';
if (isset($ _ POST [' 更新'])&& $ _POST [' update']!= < span class =code-string> )
{
$ id = $ _POST [' vid'];
$ sql = SELECT * FROM demo where id ='$ id';
$ result = mysqli_query($ con,$ sql);
包括' edit.php';
}
edit.php
<?php
echo ' < span class =code-string> edit.php';
if(isset($ result))
{
while($ row = mysqli_fetch_array($ result))
{
echo $ row [' id']; < br>';
echo $ row [' name']; ' < br>';
echo $ row [' firstname']; ' < br>';
echo $ row [' age']; ' < br>';
}
}
谢谢
maideen
sql = 通过id; SELECT * FROM演示订单;
尝试 {
结果 = mysqli_query(
con,
Hi
I am new, Pls help me the following issue. When click the update button, ID should be to another page to process the update function. Below is my entire code
index.php
<?php
include_once '../../inc/config.inc.php';
$sql="SELECT * FROM demo order by id";
try {
$result = mysqli_query($con,$sql);
include 'view.html.php';
}
catch (PDOException $e)
{
echo $e->getMessage() . "\n";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
// $output = 'Error fetching authors from database!';
// include '../../notification/errormsg.php';
exit();
}
view.html.php
<Script Language="javascript">
function change_action()
{
var frm_obj=document.getElementById("frm");
frm_obj.action="data.php";
}
</Script>
<h3>User Details</h3>
<form action="" method="POST" id="frm" >
<table width="100%" align="center" cellpadding="4" cellspacing="1">
<tr>
<td>ID</td>
<td>ID</td>
<td>NAME</td>
<td>FIRST NAME</td>
<td>AGE</td>
<td></td>
</tr>
<?php
if(isset($result)){
while($row = mysqli_fetch_array($result)){ ?>
<tr>
<td><input type="text" name="vid" value="<?php echo $row['id'];?>"/></td>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['age'] ;?></td>
<td><input type="submit" value="update" name="update" onclick="change_action()">
<input type="submit" value="delete" name="delete" onclick="change_action()">
</td>
</tr>
<?php
}
}
mysqli_close($con);
?>
</table>
</FORM>
<?php
include '../../inc/footer.php';
data.php
<?php
include_once '../../inc/config.inc.php';
if (isset($_POST['update']) && $_POST['update'] != "" )
{
$id = $_POST['vid'];
$sql="SELECT * FROM demo where id='$id'";
$result = mysqli_query($con,$sql);
include 'edit.php';
}
edit.php
<?php
echo 'edit.php';
if(isset($result))
{
while($row = mysqli_fetch_array($result))
{
echo $row['id'];'<br>';
echo $row['name'];'<br>';
echo $row['firstname'];'<br>';
echo $row['age'];'<br>';
}
}
thank you
maideen
sql="SELECT * FROM demo order by id"; try {
result = mysqli_query(
con,
这篇关于如何将id发布到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!