2016-05-23 11 views
0

我有一个很少输入字段和更新选项的形式,假设如果我有10个字段,我只更新前两个字段,而不是其他谁可以我显示仅第一到字段A和B使用PHP和mysqli的如何找到哪个字段已被更新的形式使用PHP和MYSQLi

enter image description here

在屏幕截图,如果我更新票据ID的值和原点我应该以某种其它页面显示消息出更新的消息这表示帐单编号和来源已更新为“xyz”值

+0

分享你的尝试至少。这可以通过多种方式完成。 – C2486

+0

我没有尝试,因为我不知道它。可以分享你的想法。可以通过一些mysli查询运行,我将能够获得列出的字段名称 – user3005758

回答

-1

好吧,它会是这样的..

HTML:

<html> 
    <body> 
//action is defining the php file's name which the form will be sent to ; 
//method is defining the method which the form will be sent with 

    <form action="updateCheck.php" method="post"> 
    <input type="text" name="input-filed-1"/> 
    <input type="text" name="input-filed-2"/> 
    <input type="text" name="input-filed-3"/> 
    <input type="text" name="input-filed-4"/> 
    <input type"text" name="input-filed-5"/> 
    <input type="submit" value="submit/> 
    </form> 
    </body> 
    </html> 

在同一目录下创建一个名为updateCheck.php文件,并输入以下代码

 <?php $updateMessage = "you have updated the following fields"; 
     for($x = 0 ; $x<=5 ; $x++) 
     { 
// trim for erasing the whitespaces 
// that if clause checks if there was data entered in the update input fields 
     if(isset($_POST["input-field-".$x]) && trim($_POST["input-field-".$x])) 
     { 
     $updateMessage.= "input-field-".$x ; 
     } 
     } 
     echo "<script type='text/javascript'>alert('".$updateMessage."')</script>" 
    ?> 

我没有测试的代码..但仔细研究它,你会看到它是如何完成的

0

一种方法是获取真正的和旧的名称字段,即

Select name,name as old_name from table 

在HTML

<input type="text" name="name" value="name from db"> 
<input type="hidden" name="old_name" value="old_name from db"> 

提交表单后,您可以通过检查。

并检查后。

If(post['name']==post['old_name']) 

就是这样。

另一种方法是从js通过检查onchange事件

+0

谢谢。真正的和旧的名字似乎是一个很好的解决方案,但我有大约40场。如果我得到更好的解决方案,这将是很好的 – user3005758

+0

另一种方式是从JS,但它应该由您至少发起。你之前说过你只有10个字段。 – C2486

相关问题