我有php页面,我在其中输入数字的文本字段。数据存储在数据库中。我需要获取在文本字段中输入的数字,以便在下一页中自动显示该数字,以解决用户无法对其进行修改的地方。请建议我如何使用php,jquery做到这一点。请告诉我我该怎么做。然后在第二页中输入的值将适合我在第一页中输入的数字并适合数据库。

//first page
<table border="0" style="border-collapse:collapse;" align="center">
<tr>
<td>
<div id="col1" align="center"><br />
 <form method="post" action="user.php">
<label type="text" name="name" maxlength="50" size="30" class="label">Enter the Membership Number</label><br />
<input type="text" name='id' placeholder="enter Membership Number" class="input" size="40"/><br />
<span class="field">(* Required field)</span><br /><br />
<input type="submit" name="submit" value="SUBMIT" class="button"><br /><br /><br /><br />
</form>
</body>
</html>

<?php
mysql_connect("localhost","root","");
mysql_select_db("anthonys");
if(isset($_POST['submit']))
{
$id= $_POST['id'];
if( ! ctype_alnum($id) )
  die('invalid id');


$query = "SELECT uid FROM `payment` WHERE `uid` =$id";


$run = mysql_query($query);

echo $id;
if(mysql_num_rows($run)>0){

echo "<script>window.open('member1.php','_self')</script>";

}
else {

    echo "<script>alert('Login details are incorrect!')</script>";
    }
}
?>

//second page

$(function() {
        $("#XISubmit").click(function(){

   var uid=document.forms["XIForm"]["uid"].value;
        var fathername = document.forms["XIForm"]["fathername"].value;


        if(fathername == null || fathername == "")
    {
        alert("Please Enter  Father's Name");
        return false;
    }

    document.getElementById("XIForm").submit();

        });
            if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
            $('li').has('ul').mouseover(function() {
                $(this).children('ul').show();
            }).mouseout(function() {
                $(this).children('ul').hide();
            })
        }
;
    });

</script></head>



<section id="sheet"  style="background-color: Transparent;">

<div id="content_inner">


<header id="header_inner">St. Anthony's Parish Education Fund
<br /><b style="font-size:15px;">Bangalore 560 095</b><br /><img src="images/line1.jpg" alt="" /></header>



<div id="col2">
<h2>Application for the Membership</h2><br /><br />
<table border="0px" style="border-collapse:collapse; width:810px;" align="center">
<tr>
<td>
<form name="XIForm" id="XIForm" method="POST" action="pdf/pdf1.php">
<input type="text" name="uid" />
<label type="text" name="fathername" maxlength="50" size="30" class="label">Father's Name</label><br />
<input  name="fathername" placeholder="" class="input" size="40"/><br /><br />







    <input type="hidden" name="formType" id="formType" value="reg"/>
        <input type="button" name="XISubmit" id="XISubmit" value="ADD" class="button" />


<br /><br /><br /><br />
</form></td>


此代码不会从第一页获取值。

最佳答案

像这样通过url传递数字

if(mysql_num_rows($run)>0){
echo "<script>window.open('member1.php?id=".$id."','_self')</script>";
}


在要显示此值的页面中,执行以下操作:

1)接受url中的ID

if(isset($_GET['id'])
 $id=$_GET['id'];


2)在文本框中显示值。

<input type="text" name="id" id="id" value="<?php if(isset($_GET['id']) { echo $id; } ?>"  readonly>


3)您可以将此文本框与其他表单元素一起添加到表单中,并且可以像往常一样通过表单传递此ID。

<form action="youractionpage.php" method="post">
ID <input type="text" name="id" id="id" value="<?php if(isset($_GET['id'])) { echo $id; } ?>"  readonly>
Amount <input type="text" name="amount">
Name  <input tpye="text" name="name">
<input type="submit" value="Submit">
</form>

关于php - 从数据库中获取的数据存储在文本字段中时,如何自动移动下一页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23774480/

10-11 02:08
查看更多