-1

i want get text input value from php web file for save values to database, but text input not work with php file. And show this error:

Notice: Undefined index: txtUsername in C:/...... line 7 Notice: Undefined index: txtPassword in C:/...... line 8

my html:

<form  action="../Controller/LoginController.php">
    <input type="text" id="txtUsername" />
    <input type="text" id="txtPassword"  />
    <input type="submit" name="btnLogin" value="login" />
</form>

my php file:

$strUsername = $_POST["txtUsername"];  //line 7
$strPassword = $_POST["txtPassword"];  //line 8
Danilo
  • 91
  • 1
  • 1
  • 9

2 Answers2

0

Form input ID can't be used for getting the value. You need to set the name attribute.

Like that:

<input type="text" name="txtUsername" /> // Notice the name attribute

You can then get the value normally.

$strUsername = $_POST["txtUsername"];
0

You're referencing it via $_POST in the PHP code, but not specifically passing it via POST in your HTML.

You also need to specify the NAME parameter, since that's what gets referenced by PHP, not ID

Try this:

<form action="../Controller/LoginController.php" method="post">
    <input type="text" id="txtUsername" name="txtUsername" />
    <input type="text" id="txtPassword" name="txtPassword"  />
    <input type="submit" name="btnLogin" value="login" />
</form>
Bing
  • 3,071
  • 6
  • 42
  • 81