user5857398 user5857398 - 7 months ago 22
PHP Question

Why i get the notice "Undefined index" if they are in the url post

i get the Notice "Undefined index" but in the url I can see, that the fields are not empty. See yourself:

URL:

http://localhost/projektarbeit/version-03/send.php?vorname=asdf&name=asdf&strasse=asdf&hausnr=12&plz=12435&ort=asdf&email=asdf%40gmail.com


Notices:

Notice: Undefined index: vorname in C:\xampp\htdocs\projektarbeit\version-03\send.php on line 5

Notice: Undefined index: name in C:\xampp\htdocs\projektarbeit\version-03\send.php on line 6

Notice: Undefined index: strasse in C:\xampp\htdocs\projektarbeit\version-03\send.php on line 7

Notice: Undefined index: hausnr in C:\xampp\htdocs\projektarbeit\version-03\send.php on line 8

Notice: Undefined index: plz in C:\xampp\htdocs\projektarbeit\version-03\send.php on line 9

Notice: Undefined index: ort in C:\xampp\htdocs\projektarbeit\version-03\send.php on line 10

Notice: Undefined index: email in C:\xampp\htdocs\projektarbeit\version-03\send.php on line 11


Here's some code:

<form action="send.php" action="POST">
<input type="text" name="vorname" pattern="{20}" required>
<input type="text" name="name" pattern="{20}" required>
<input type="text" name="strasse" pattern="{20}" required>
<input type="text" name="hausnr" pattern="[a-zA-Z0-9]+{5}" required>
<input type="text" name="plz" pattern="[0-9]{5}" required>
<input type="text" name="ort" pattern="{20}" required>
<input type="email" name="email" required>
<input type="submit">
</form>


And my PHP-Script:

<?php
include 'includes/db-connection.php';

$vorname = $_POST['vorname'];
$name = $_POST['name'];
$strasse = $_POST['strasse'];
$hausnr = $_POST['hausnr'];
$plz = $_POST['plz'];
$ort = $_POST['ort'];
$email = $_POST['email'];
?>


Hope somebody can help me :s

Answer

The correct way to make a post submit is the use the method tag and not action tag.

Action contains your url : send.php and method : post

<form method="post" action="send.php">

</form>