0

I have done this from one of the youtube channel .. ii just copied all the code but still its not working. can you anyone can help me on this. I have facing the error at end saying NOT INSERTED.

**index.php**
<html>
<head>
    <title>Data entry practise</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <div class="wrapper">
        <form action="insert.php" method="_POST">
            Name: <input type="text" name="username"><br><br>
            Email Address: <input type="text" name="email"><br><br>
            <input type="submit" value="insert">

        </form>
        </div>

</body>
</html>

Now this is the inset.php code section. seems like here is some error .. please help me out

**insert.php**
<?php 

$con = mysqli_connect('localhost','root','');


if(!$con)
{
echo "not connected";
}

if(!mysqli_select_db($con,'tutorial'))
{
echo 'database Note Selected';
}

$Name = $_POST['username'];
$Email = $_POST['email'];

$sql = "INSERT INTO person (Name,Email) VALUES ('$Name', '$Email')";

if(!mysqli_query($con, $sql))
{
echo "Not Inserted";
}
else 
{
echo "Inserted";
}

 ?>
Raviprakash
  • 2,410
  • 6
  • 34
  • 56
  • 2
    Possible duplicate of [PHP error: Notice: Undefined index:](https://stackoverflow.com/questions/4465728/php-error-notice-undefined-index) – tkausl May 08 '18 at 10:32
  • Please answer me from the context of my code if i would have figured out looking other posts than i would not had post it here.. so please help me watching the code and solving it – Shubheksha Pokhrel May 08 '18 at 10:45
  • There are rules against duplicating posts. Your post should be closed. If you do not know how to fix your problems by reading similar posts then maybe you shouldn’t do software engineering. – Y2H May 08 '18 at 12:17

1 Answers1

0

The problem is that the form method is incorrect. You have to write it without the underscore

**index.php**
<html>
<head>
    <title>Data entry practise</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <div class="wrapper">
        <form action="insert.php" method="POST">
            Name: <input type="text" name="username"><br><br>
            Email Address: <input type="text" name="email"><br><br>
            <input type="submit" value="insert">

        </form>
        </div>

</body>
</html>

EDIT:

I think the problem is on your mysql connection. You need to add the db on the $con variable, like this:

insert.php

$con = mysqli_connect('localhost','root','', 'tutorial');


if(!$con)
{
echo "not connected";
}

if(!mysqli_select_db($con,'tutorial'))
{
echo 'database Note Selected';
}

$Name = $_POST['username'];
$Email = $_POST['email'];

$sql = "INSERT INTO person (Name,Email) VALUES ('$Name', '$Email')";

if(!mysqli_query($con, $sql))
{
echo "Not Inserted";
}
else 
{
echo "Inserted";
}

 ?>

I tested with your code and it is working.

One more thing, you need to change the form method to "POST", without underscore, it is important.

istaro
  • 139
  • 1
  • 12