-2

This is my basic form:

<form class="table" action="signup.php" method="POST">
        <input type="text" name="Name"  value="" placeholder="Enter Ur name"><br>``
        <input type="text" name="username"  value="" placeholder="Enter Username" minlength="10" required><br>
        <input type="password" name="pwd"  value="" placeholder="Enter password" minlength="8" required><br>
        <input type="date" name="dob"  value="" placeholder="Enter DOB" required><br>
        <input type="hidden" name="form_submitted" value="1"/>
        <input type="submit" value="signup" name="submit" />

Then I connect to the database with connect.php then my signup.php code looks like this:

include ('connect.php');
$submit=filter_input(INPUT_POST, submit);
if(isset($submit))
{
  $name=filter_input(INPUT_POST, Name);
  echo "Your name is". $name;
  $uname=filter_input(INPUT_POST, username);
  $pwd=filter_input(INPUT_POST, pwd);
  $dob=filter_input(INPUT_POST, dob);
  $query="insert INTO form1(Name,uname,Password,DOB) values('$name','$uname','$pwd','$dob')";
  if(mysql_query($query))
  {
    echo "Information saved successfully";
  }

Now if I want to use $name=$_POST['Name'] it is showing you can't access superglobal directly so I use filter input.

After using filter_input it showing undefined constant error for Name,pwd,uname,and dob. So I think and go for is my form submitted because it doesn't know what is Name,pwd,dob,uname.So then please reply with your answers and help me. Finally i need to store the values in database is my motive.

Nick
  • 1,032
  • 16
  • 27
  • submit and Name should be string I guess. Filter_input have second parameter as string. Put it all to double quotes. – daremachine Oct 21 '17 at 02:49
  • 1
    Please do proper research before asking. Typing part of your question title into Google would have lead you to plenty of answers already, such as https://stackoverflow.com/questions/7711466/checking-if-form-has-been-submitted-php – CBroe Oct 21 '17 at 02:53
  • You not closing your `if(isset($submit))` – Nick Oct 21 '17 at 03:02
  • @daremachine:: submit and Name are names of input fields which i wanted to store them in variables.I had tried putting them in double quoted but it doesnt took values entered in form input – chaitanya krishna Oct 21 '17 at 03:28
  • @Nick I had closed isset function but it doesn't worked out.Any suggestion? – chaitanya krishna Oct 21 '17 at 03:30
  • Perhaps your superglobals warning is from your editor: https://stackoverflow.com/questions/19767894/warning-do-not-access-superglobal-post-array-directly-on-netbeans-7-4-for-ph – Progrock Oct 21 '17 at 05:58

1 Answers1

0

You should quote your second parameter for filter_input. Otherwise Php will type juggle and emit a notice.

$name   = filter_input(INPUT_POST, Name);

Notice:

PHP Notice:  Use of undefined constant Name - assumed 'Name'.

Your code may however still work as expected.

The following works for me:

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $name   = filter_input(INPUT_POST, 'Name');
    $uname  = filter_input(INPUT_POST, 'username');
    $pwd    = filter_input(INPUT_POST, 'pwd');
    $dob    = filter_input(INPUT_POST, 'dob');

    var_dump($name, $uname, $pwd, $dob);
    //store_form_values($name, $uname, $pwd, $dob);
}
?>
<form method="post">
    <input type="text" name="Name"  value="" placeholder="Enter Ur name"><br>   
    <input type="text" name="username"  value="" placeholder="Enter Username" minlength="10" required><br>
    <input type="password" name="pwd"  value="" placeholder="Enter password" minlength="8" required><br>
    <input type="date" name="dob"  value="" placeholder="Enter DOB" required><br>
    <input type="submit" value="signup" name="submit" />
</form>

Note no actual input filtering occurs by default with filter_input. So you must take care with user submitted data. Escaping appropriately when outputting values in your scripts or when storing in your database.

Further the mysql_* database functions are deprecated. Alternatively look at mysqli or pdo.

Progrock
  • 7,373
  • 1
  • 19
  • 25