-3

I have a form in HTML, in which I am pulling values from with PHP. I would like to insert it into a database with SQL, but (from my experience with this issue, at least) you can't insert $_POST values with an SQL statement.

When the page is loaded on XAMPP, I get the following error of:

Notice: Undefined index: email in C:\xampp\htdocs\index.php on line 26

My code looks something like this:

<form method="post">
  <input type="text" placeholder="Firstname" name="email">
  <button class="btndef" name="submit">Submit</button>
  </form>

<?php
$email = $_POST['email'];
?>

Obviously something's wrong with it, but I have no idea what!

dferenc
  • 7,918
  • 12
  • 41
  • 49
whoff
  • 154
  • 13

1 Answers1

1

You can try this.

<?php if(isset($_POST['submit']){
    $email = $_POST['email']; 
?>

<form method="post" action="action-url">
  <input type="text" placeholder="Firstname" name="email">
  <button class="btndef" type="submit" name="submit">Submit</button>
</form>

Make sure you are doing validation while submitting the form

BEingprabhU
  • 1,618
  • 2
  • 21
  • 28
  • Yes but I want to send to phpMyAdmin, so this wouldn't work for me – whoff Feb 09 '18 at 22:04
  • PHPMyAdmin is just a User Interface for MySQL. It has nothing to do with your operation. Can you elaborate little that where you are getting the problem?? Any errors?? Please update your question. – BEingprabhU Feb 10 '18 at 04:32