简体   繁体   中英

Html form cannot pass to php

passing-var.php

`<form method="post" action="catching-var.php">
 <input type="text" name="name1"/><br/>
 <input type="text" name="name2"/><br/>
 <input type="text" name="name3"/><br/>
 <input type="text" name="name4"/><br/>
 <input type="submit" name="submit"/>
  </form>`

catching-var.php

<?php 
 $name0 = $_POST['name0'];
 $name1 = $_POST['name1']; 
 $name2 = $_POST['name2']; 
 $name3 = $_POST['name3']; 
 $name4 = $_POST['name4'];

 echo $name0.'<br/><br/>'; 
 echo $name1.'<br/><br/>'; 
 echo $name2.'<br/><br/>'; 
 echo $name3.'<br/><br/>'; 
 echo $name3.'<br/><br/>';
 ?>

I have search for most of the websites about html form passing variable through php variable.. I do not understand why my form from passing-var.php cannot pass the variable to catching-var.php.. I have check the codes for several times and still can't find out what is the problem.. Helps will be appreciated.. Thank You.. PS: I am very new to php and in the learning stage

You need to check that a POST variable is set before you try to use it. So as you haven't included in your form, you're going to get an error when you try to access it. You can check if a var has been set

$name0 = (isset($_POST['name0']) ? $_POST['name0'] : 'not set');

this doesn't exist in your form:

$name0 = $_POST['name0'];

it would probably that say $name0 is not set. but the other name variable should work fine.

in your catching-var.php try doing this.

if(isset($_POST['submit'])){

 $name1 = $_POST['name1']; 
 $name2 = $_POST['name2']; 
 $name3 = $_POST['name3']; 
 $name4 = $_POST['name4'];

 echo $name1.'<br/><br/>'; 
 echo $name2.'<br/><br/>'; 
 echo $name3.'<br/><br/>'; 
 echo $name3.'<br/><br/>';

}

also make sure your files are in the same directory.

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