如何纠正未定义的索引:第12行的C:\ wamp64 \ www \ Form \ addtodatabase.php中的firstname错误

时间:2017-03-07 05:13:39

标签: php html post

有一个名为form.html的页面。它指向页面addtodatabase.php 最后有提交按钮。

SELECT count(DISTINCT a.client_invoice_id) 
from client_invoice a LEFT JOIN
document b on(a.client_invoice_id = b.relation_id_invoice) 
WHERE a.client_invoice_id IS NOT null
and b.type_document = 'client_invoice'

我的addtodatabase.php页面。

    <form action="addtodatabase.php" method="post">
    <form class="form-inline">
    <fieldset>
    <legend>Security Department User Registration</legend>
    <div class="form-group">
    <label for="Firstname">First Name</label>
    <input type="text" class="form-control" id="Firstname" name="firstname" placeholder="Text input"><br/>
    </div>

    <div class="form-group">
    <label for="Secondname">Second Name</label>
    <input type="text" class="form-control" id="Secondname" name="secondname" placeholder="Text input"><br/>
    </div>
    </form>

有三个错误

  

它没有到达页面 $connect=mysqli_connect('localhost','root','','form_db'); if(mysqli_connect_errno($connect)) { echo 'Failed to connect:'.mysqli_connect_error(); } $firstname=""; $secondname=""; if (isset($_POST)) { $firstname = isset($_POST['firstname']) ? $_POST['firstname'] : ''; $secondname = isset($_POST['secondname']) ? $_POST['secondname'] : ''; echo 'Your first name is ' .$firstname. '<br>'; echo 'Your second name is ' .$secondname. '<br>'; } 。   http://localhost:8080/form/form.html
  注意:未定义的索引:第12行的C:\ wamp64 \ www \ Form \ addtodatabase.php中的firstname。   没有任何东西被添加到数据库。只有id是增量

提前致谢。

3 个答案:

答案 0 :(得分:0)

注意 - 在获取数据之前检查isset。

试试这个

func viewDidLoad() {

    //Define Layout here
    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()

    //Get device width
    let width = UIScreen.main.bounds.width

    //set section inset as per your requirement.
    layout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)

    //set cell item size here 
    layout.itemSize = CGSize(width: width / 2, height: width / 2)

    //set Minimum spacing between 2 items
    layout.minimumInteritemSpacing = 0

    //set minimum vertical line spacing here between two lines in collectionview
    layout.minimumLineSpacing = 0

    //apply defined layout to collectionview
    collectionView!.collectionViewLayout = layout

}

答案 1 :(得分:0)

是addtodatabase.php与form.html相同的文件夹吗?

如果html位于c:\ wamp64 \ www并且addtodatabase.php位于C:\ wamp64 \ www \ Form \中,则将html更改为;

<form action="Form/addtodatabase.php" method="post">
<form class="form-inline">
<fieldset>
<legend>Security Department User Registration</legend>
<div class="form-group">
<label for="Firstname">First Name</label>
<input type="text" class="form-control" id="Firstname" name="firstname" placeholder="Text input"><br/>
</div>

<div class="form-group">
<label for="Secondname">Second Name</label>
<input type="text" class="form-control" id="Secondname" name="secondname" placeholder="Text input"><br/>
</div>
</form>
<input type="submit" value="submit">
</form>

答案 2 :(得分:0)

在访问帖子值之前,最好检查一下它是否存在。所以使用

$firstname  = isset($_POST['firstname']) ? $_POST['firstname'] : '';
$secondname = isset($_POST['secondname']) ? $_POST['secondname'] : '';

替换

$firstname=$_POST['firstname'];
$secondname=$_POST['secondname'];

编辑:

$connect=mysqli_connect('localhost','root','','form_db');

if(mysqli_connect_errno($connect))
{
echo 'Failed to connect:'.mysqli_connect_error();
}


$firstname  = isset($_POST['firstname']) ? $_POST['firstname'] : '';
$secondname = isset($_POST['secondname']) ? $_POST['secondname'] : '';

echo 'Your first name is ' .$firstname. '<br>'; 
echo 'Your second name is ' .$secondname. '<br>'; 
}