Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>

        <form action="" method="post" >
    Name:<input type="text" name="un"> <br>
    Password:<input type="password" name="un2"/> <br>
    <input type="submit" value="submit" name="submit" />
</form>
    </head>
    <body>
        <?php

        if ($_POST['submit']) {
        mysql_connect ("localhost", "root", "promod19861030") or die ('Error: ' . mysql_error());
        mysql_select_db("empdata") or die ('Data error:' . mysql_error());
        $text = mysql_real_escape_string($_POST['un']);
        $query="INSERT INTO empname (empName) VALUES ('$text')";
        mysql_query($query) or die ('Error updating database' . mysql_error());

}
        ?>
    </body>
</html>



it gives this error as well?

Notice: Undefined index: submit in C:\xampp\htdocs\PhpProject1\index.php on line 16

Line 16 is this :-

PHP
if ($_POST['submit']) {


if i input data to the two textboxes and i hit the submit button
the data will store into the database twice.

Please tell me what is the problem in the code?
Posted

1 solution

I solved it myself...............

XML
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>

        <form action="" method="post" >
    Name:<input type="text" name="un"> <br>
    Password:<input type="password" name="un2"/> <br>
    <input type="submit" value="submit" name="submit" />
</form>
    </head>
    <body>
        <?php

        if (isset($_POST['submit'])) {
        mysql_connect ("localhost", "root", "promod19861030") or die ('Error: ' . mysql_error());
        mysql_select_db("empdata") or die ('Data error:' . mysql_error());
        $text = mysql_real_escape_string($_POST['un']);
        $query="INSERT INTO empname (empName) VALUES ('$text')";
        mysql_query($query) or die ('Error updating database' . mysql_error());

}
        ?>
    </body>
</html>


Thanks everyone for the attention!!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900