0

Well, have been recently learning PHP for a project. So, to practice, I'm trying forms: The HTML code:

<!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>

And the PHP code:

<!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>

When I tried to use it, it gives me this:

Notice: Undefined index: emri in G:\USB WEB Server\root\butoni\form.php on line 7

Notice: Undefined index: mbiemri in G:\USB WEB Server\root\butoni\form.php on line 8

Notice: Undefined index: adresa in G:\USB WEB Server\root\butoni\form.php on line 9

Notice: Undefined index: numri in G:\USB WEB Server\root\butoni\form.php on line 10

Notice: Undefined index: email in G:\USB WEB Server\root\butoni\form.php on line 11

Notice: Undefined index: pershkrim in G:\USB WEB Server\root\butoni\form.php on line 12 Help please? Thank you in advance.

5 Answers5

2

Change your form method from:

 <form action="form.php" method="get">

to:

<form action="form.php" method="post">
Leonardo
  • 736
  • 4
  • 11
2

You have your form on

method="get">

So in PHP you should use $_GET insted of $_POST.

Or better yet, set method to

method="post">

Because you are posting to form.php

Patrick Aleman
  • 612
  • 6
  • 19
0

Change your method to POST and your indexes will become valid ie defined.

Artur
  • 7,038
  • 2
  • 25
  • 39
0

Try it 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; ?>
Baron
  • 379
  • 3
  • 9
0

Your php code should be inside if(!empty($_POST)){} Example:

<?php
if(!empty($_POST)){
    $emri=$_POST["emri"];
    $mbiemri=$_POST["mbiemri"];
    $adresa=$_POST["adresa"];
    $numri=$_POST["numri"];
    $email=$_POST["email"];
    $pershkrim=$_POST["pershkrim"];
    echo $emri;
}
?>
Hariprasad Prolanx
  • 2,762
  • 1
  • 16
  • 13