简体   繁体   中英

How do I let php know that I made changes In input?

Well I have this 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"; }?>
and changes php:
 <form action="changes.php" method="POST"> <input type="text" name="goose"> <input type="text" name="cat"> <input type="submit" name="do_change"> </form>

I need if <input name="goose" value="hey"> and <input name="cat" value=""> display text:"you have wrote something in input with name goose and nothing with name cat"

To check if the user filled out more than one of your text input fields, you can for example do something like this:

// 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.';
}

You forgot {}

First page:

<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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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