提问者:小点点

我如何让php知道我在输入中做了更改?


我有这样的HTML:

<?php
        if(isset($_POST['do_change'])) {
        // that is the place where i need to place if(changes have been made in input)
        echo "yeey y made changes";
     }
        ?>
 
       <form action="changes.php" method="POST">
        <input type="text" name="goose">
        <input type="text" name="cat">
        <input type="submit" name="do_change">
        </form>

null

我需要显示文本:“您在输入中使用名称goose编写了一些东西,而使用名称cat编写了什么东西”


共2个答案

匿名用户

要检查用户是否填写了多个文本输入字段,例如,您可以执行以下操作:

// array with names of the fields you want to check
$fieldnames = ['goose', 'cat', 'kangaroo'];

// initialize counter of filled fields with 0
$filled = 0;

// loop over the field names
foreach($fieldnames as $fieldname) {
  // check if a value under that name exists in the $_POST array,
  // and if so, that its value is not the empty string
  if(isset($_POST[$fieldname]) && $_POST[$fieldname] !== '') {
    $filled++;
  }
}

if($filled > 1) {
  echo 'You filled more than one field.';
}

匿名用户

您忘了{}

第一页:

<form action="changes.php" method="POST">
<input type="text" name="goose">
<input type="submit" name="do_change">
</form>

changes.php:

if(isset($_POST['do_change'])){
// that is the place where i need to place if(changes have been made in input)
echo "yeey y made changes";
}