How do you get input from the text field in the following code?
<?php
echo "<form action='signup.php' method='POST'>";
echo "<input type='text' placeholder='Username' name='username'/>";
echo "<button type='submit' name = 'submit' value='Register' >Sign up</button>";
echo "</form>";
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password,"vaccinations");
$Iusername = $_POST['username'];
if(isset($_POST['submit'])){
$Iusername = $_POST['username'];
echo $Iusername;
echo "whadddup";
}
?>
This is giving me username is an undefined index. I need to grab the inputted data in the text field that was echoed
$conn, you have$Iusername = $_POST['username'];. And for every time you access this code and don't submit the form (when you first access it), it will generate that warning. Simple fix: Remove that line, because you define it within theif(isset($_POST['submit'])){(no need to define it twice)$Iusername = $_POST['username'];remove it, because you have it inif(isset($_POST['submit'])){condition and that is enough