繁体   English   中英

表格,使用php从mysql检索数据,并在同一HTML页面中填充另一表格

[英]Form which retrieves data from mysql using php and fills another form in the same HTML page

我有一个html页面,该页面从一种形式(例如form1)获取数据,并使用php(单击“提交”)将其存储在mysql数据库中。 现在,我正在使用另一种形式,即form2,如果它已经存储在数据库中,则自动填写form1中的输入字段。

因此,我在form2中提供了两个字段,并编写了一个“ match.php”来尝试在mysql数据库中搜索记录。 当我在form2上单击“提交”时,将运行此命令。 我还包含在“ match.php” js脚本中,以更改表格1的值属性。

但是问题是当我在form2的总和上计时时,显示空白页。 如果找到匹配项,我希望填入form1中的文本框!

match.php

$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$a=$_POST['empname'];
$b=$_POST['vid'];
$sql = "SELECT * FROM table1 where name='$a' AND visitorid='vid'";
$result = mysqli_query($conn, $sql);

while($row = mysqli_fetch_assoc($result))
$b=$row['number'];

echo "
<script>
var form1 = document.forms[0];
var form2 = document.forms[2];

var number= form1.elements['n11'];

number.value=".$b."";
echo " </script>";

form1中

    <form enctype="multipart/form-data" action="con3.php" method="post">

    <table>
        <tr rowspan="500" colspan="500">
        <td>
        <input type='file' name="userfile" onchange="readURL(this);"/>
            <img id="blah" src="#" alt="your image" />
        </td>
        </tr>

        <tr colspan="2" rowspan="2">
        <td>VISITOR'S ID</td>
        <td><input type="textbox"   id="t1"  value="automatically generated"    name="n1"   onfocus="this.blur()"/></td>

        <tr colspan="2" rowspan="2">
        <td>NAME OF THE EMPLOYEE</td><span style="color:red;">*</span>
        <td><input type="textbox"   id="t4"     name="n4"   onblur="f4()"/><span style="color:red;">*</span></td>
        </tr>

        <tr colspan="2" rowspan="2">
        <td>ID PROOF</td>
        <td>
        <select                     name="n20"  onblur="f38()" >
        <option>id</option>
        <option>1210312117</option>
        </select>
        </tr>

        <tr colspan="2" rowspan="2">
        <td>CONTACT NUMBER ON EMERGENCY</td><span style="color:red;">*</span>
        <td><input type="textbox"   id="t14"    name="n11"  onblur="f14()" required/><span style="color:red;">*</span></td>
        </tr>

        <tr colspan="2" rowspan="2">
        <td>INTIME</td>
        <td><input type="textbox"   id="t17"    name="n16"  onblur="f17()"/></td>
        <td><input type="button" value="PICKTIM" id="t18" onclick="document.getElementById('t17').value = f88()"/></td>
        </tr>

        <tr colspan="2" rowspan="2">
        <td>OUTTIME</td>
        <td><input type="textbox"   id="t100"   name="n17"  onblur="f100()"/></td>
        </tr>

        <td><input type="submit" value="SAVE RECORD"    id="t25"    onclick="f25()"/></td>
        </tr>
</table>

窗口2

<form action="match.php" method="post">
<h3> Old employee?</h3>

    Name of the emplyee: <input type="text" name="empname" id="id1" /></br>
    Visitor id: <input type ="text" name="vid" id="id2"/> <br/>
    <input type="submit" value="submit"/>
    </form>

将您的SQL数据结果(您获取-> assoc())存储在$ _SESSION对象中,如下所示:

//Before the DOCTYPE and every other line
<?php session_start(); ?>

//In your php code :
$row = mysqli_fetch_assoc($result->empname)
//I don't use this method of PHP for databases, I use PDO, but the result is the same and so I don't know if this is above is really correct
//but you seem to know what to do
$_SESSION["empname"] = $empname;

//And in your form2
Name of the employee : <?php echo $_SESSION["empname"]; ?>

要在“提交”按钮之后显示对象,请使用session_start()在页面上启动会话。 您可以通过echo $ _SESSION [“ object_name”];显示它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM