-1

Here is my form code ,

 <form role="form" id="order-form" action="db.php" method="post">
            <div class="form-group">
            <label for="name">Name</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Your Full Name">
            </div>
                <div class="form-group">
            <label for="address">Delivery Address</label>
    <textarea class="form-control" rows="3" id="address" name="address" placeholder="Address" ></textarea>

                </div>
              <div class="form-group">
             <label for="phone">Phone No</label>
        <input type="text" class="form-control" id="phone" name="mobile" placeholder="Phone No">
        </div>
       <div class="form-group">
        <label for="email">Email address</label>
      <input type="email" class="form-control" id="email" name="email" placeholder="Enter email">
    </div>
    <div class="form-group">
    <label for="exampleInputEmail1">Quantity</label>
    <select class="form-control" id="quantity" name="quantity">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
    </select>
    </div>
    <div class="form-group" >
    <label for="exampleInputEmail1">Expected Date</label>
        <input id="datepicker" name="date" >
        </div>


      <button type="submit" class="btn btn-default" >Submit</button>
    </form>

THis is my db.php .

<?php
$con=mysqli_connect("localhost","root","","honey");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO pre_order
            (name,delivery_location,mobile,email,qty,workdt)
            VALUES
            ('$_POST[name]','$_POST[address]','$_POST[mobile]','$_POST[email]','$_POST[quantity]','$_POST[date]')";
if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
//'echo "Order Received";

mysqli_close($con);
?>

when I click on submit form , It says

PHP Notices:

Notice: Undefined index: address in C:\xampp\htdocs\office_work\ironbull2\ironbull\db.php on line 12

Notice: Undefined index: date in C:\xampp\htdocs\office_work\ironbull2\ironbull\db.php on line 12

The date picker I have used here is a jquery ui plugin .

Kumar V
  • 8,810
  • 9
  • 39
  • 58
Shuvro Shuvro
  • 119
  • 1
  • 3
  • 10
  • can you do a print_r($_POST) and see if the form elements are in POST ? – Abhik Chakraborty Jan 11 '14 at 16:42
  • First check what your $_REQUEST contains, put `echo "
    ";print_r($_REQUEST);exit;` at the beginning to see if your PHP page receives the date field.
    BEFORE RUNNING IN PRODUCTION avoid sql-injections... I suggest you this discussion: http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php
    – matteospampani Jan 11 '14 at 16:45

2 Answers2

2

You are not wrapping your array key reference in quotes.

$_POST[name]

Should be

$_POST['name']

It is treating them as constants.

SamV
  • 7,548
  • 4
  • 39
  • 50
-1

It was because you didn't pass the value to the $_POST array.

before submit you need to check those variable have the value or not.

OR

you can add '@' in front of the post. LIKE:

@$_POST[name]

chen
  • 407
  • 2
  • 9