1

Trying to insert data into a table with the following code :

if ($valid) {
            $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "INSERT INTO customers (FName, LName, JAddress, BAddress, Phone, APhone, Email, AEmail) values(?, ?, ?, ?, ?, ?, ?, ?);";
            $q = $pdo->prepare($sql);
            $q->execute(array($FName,$LName,$JAddress,$Baddress,$Phone,$APhone,$Email,$AEmail,$id));
            Database::disconnect();
            header("Location: index.php");
        }

values

// keep track post values
        $id       = $POST['id'];
        $FName    = $_POST['FName'];
        .....etc

form

<div class="control-group <?php echo !empty($nameError)?'error':'';?>">
                        <label class="control-label">ID</label>
                        <div class="controls">
                            <input name="id" type="text"  placeholder="ID" value="<?php echo !empty($id)?$id:'';?>">
                            <?php if (!id($idError)): ?>
                                <span class="help-inline"><?php echo $idError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>
                      <div class="control-group <?php echo !empty($FNameError)?'error':'';?>">
                        <label class="control-label">First Name</label>
                        <div class="controls">
                            <input name="FName" type="text"  placeholder="First Name" value="<?php echo !empty($FName)?$FName:'';?>">
                            <?php if (!empty($FNameError)): ?>
                                <span class="help-inline"><?php echo $FNameError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>

I get to a page that shows the ID form field, which I wanted to keep hidden, and have it of course auto increment. Below the form field I get : Call to undefined function id()

If I put in an ID # and press enter I get the following errors : Notice: Undefined variable: POST Notice: Undefined index: Phone ...etc

I know this has to be some fumble key on my part, but am not spotting it. Does anyone see where I went wrong?

Steven
  • 687
  • 1
  • 10
  • 27

1 Answers1

1

This line $id = $POST['id'];

$POST

Is missing an underscore:

$_POST

It's a superglobal http://php.net/manual/en/language.variables.superglobals.php

  • Which explains the notice.

Nota: You also have an extra argument $id in

((array($FName,$LName,$JAddress,$Baddress,$Phone,$APhone,$Email,$AEmail,$id))

which may also pose a problem.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141