我最近在为一个项目学习PHP。因此,为了练习,我尝试了以下形式:HTML代码:
<!DOCTYPE html>
<html>
<head>
<title>Raportoni</title>
<style type="text/css">
</style>
</head>
<body>
<p></br></p>
<form action="form.php" method="post">
Emri : <input type="text" name="emri">
</br></br>
Mbiemri : <input type="text" name="mbiemri">
</br></br>
Adresa : <input type="text" name="adresa">
</br></br>
Numri i telefonit : <input type="text" name="numri">
</br></br>
Email : <input type="text" name ="email">
</br></br>
Nje pershkrim i shkurter i asaj qe ju ka ndodhur : </br> <textarea name="pershkrim"></textarea>
</br>
<input type="submit" value="Dergo">
</form>
</body>
</html>
和PHP代码:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$emri=$_POST["emri"];
$mbiemri=$_POST["mbiemri"];
$adresa=$_POST["adresa"];
$numri=$_POST["numri"];
$email=$_POST["email"];
$pershkrim=$_POST["pershkrim"];
echo $emri;
?>
</body>
</html>
当我尝试使用它时,它给了我这个:
注意:未定义的索引:G:''USB WEB Server''root''buttoni''form.php中的emri在第7行
注意:未定义的索引:G:''USB WEB Server''root''buttoni''form.php中的mbiemri,位于第8行
注意:未定义的索引:第9行上G:''USB WEB Server''root''buttoni''form.php中的adresa
注意:第10行上G:''USB WEB Server''root''buttoni''form.php中的未定义索引:numri
注意:未定义的索引:第11行上G:''USB WEB Server''root''buttoni''form.php中的电子邮件
注意:第12行G:''USB WEB Server''root''buttoni''form.php中的未定义索引:pershkrim请帮忙?提前谢谢。
更改您的表单方法:
<form action="form.php" method="get">
至:
<form action="form.php" method="post">
您在上有表格
method="get">
因此,在PHP中,应该使用$_GET而不是$_POST。
或者更好的是,将方法设置为
method="post">
因为您正在发布到form.php
将方法更改为POST,索引将变为有效的即定义索引。
试试吧form.php
<?php
if(isset($_POST['emri'])){$emri=$_POST['emri'];}
if(isset($_POST['mbiemri'])){$mbiemri=$_POST['mbiemri'];}
if(isset($_POST['adresa'])){$adresa=$_POST['adresa'];}
if(isset($_POST['numri'])){$numri=$_POST['numri'];}
if(isset($_POST['email'])){$email=$_POST['email'];}
if(isset($_POST['pershkrim'])){$pershkrim=$_POST['pershkrim'];}
echo $emri; ?>
您的php代码应该在if(!empty($_POST)){}
中示例:
<?php
if(!empty($_POST)){
$emri=$_POST["emri"];
$mbiemri=$_POST["mbiemri"];
$adresa=$_POST["adresa"];
$numri=$_POST["numri"];
$email=$_POST["email"];
$pershkrim=$_POST["pershkrim"];
echo $emri;
}
?>