I am using a Crud plugin and i am having some problems.

After i modifie it for my needs i ma having a problems creating a records.

Error code is in line 186.

this is my code please help..

<?php 

    require 'database.php';

    if ( !empty($_POST)) {
        // keep track validation errors
        $locationError = null;
        $dateError = null;
        $fisrt_nameError = null;
        $last_nameError = null;
        $buildingError = null;
        $phoneError = null;
        $qosError = null;
        $salesrror = null;
        $usernameError = null;

        // keep track post values

        $location = $_POST['location'];
        $date = $_POST['date'];
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $building = $_POST['building'];
        $phone = $_POST['phone'];
        $qos = $_POST['qos'];
        $sales = $_POST['sales'];
        $username = $_POST['username'];

        // validate input
        $valid = true;
        if (empty($location)) {
            $locationError = 'Please enter Location';
            $valid = false;
        }
        if (empty($date)) {
            $dateError = 'Please enter Valid Date';
            $valid = false;

        }
        if (empty($first_name)) {
            $fisrt_nameError = 'Please enter First Name';
            $valid = false;

        if (empty($last_name)) {
            $last_nameError = 'Please enter Last Name';
            $valid = false;

        if (empty($building)) {
            $buildingError = 'Please enter Building Number';
            $valid = false;
        }
        if (empty($phone)) {
            $phoneError = 'Please enter Phone Number';
            $valid = false;

        if (empty($qos)) {
            $qosError = 'Please enter Qos';
            $valid = false;

        if (empty($sales)) {
            $salesrror = 'Please enter Sales Person Name';
            $valid = false;

        if (empty($username)) {
            $usernameError = 'Please enter customer Username';
            $valid = false;

        // insert data
        if ($valid) {
            $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "INSERT INTO customers (location,first_name,last_name,building,phone,qos,sales,username) values(?, ?, ?, ?, ?, ?, ?, ?, ?)";
            $q = $pdo->prepare($sql);
            $q->execute(array($location,$date,$first_name,$last_name,$building,$phone,$qos,$sales,$username));
            Database::disconnect();
            header("Location: index.php");
        }
    }
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link   href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">

                <div class="span10 offset1">
                    <div class="row">
                        <h3>Create a Customer</h3>
                    </div>

                    <form class="form-horizontal" action="create.php" method="post">

                      <div class="control-group <?php echo !empty($locationError)?'error':'';?>">
                        <label class="control-label">Location</label>
                        <div class="controls">
                            <input name="location" type="text"  placeholder="Location" value="<?php echo !empty($location)?$location:'';?>">
                            <?php if (!empty($locationError)): ?>
                                <span class="help-inline"><?php echo $locationError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($dateError)?'error':'';?>">
                        <label class="control-label">Date</label>
                        <div class="controls">
                            <input name="date" type="text" placeholder="Date" value="<?php echo !empty($date)?$date:'';?>">
                            <?php if (!empty($dateError)): ?>
                                <span class="help-inline"><?php echo $dateError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($fisrt_nameError)?'error':'';?>">
                        <label class="control-label">First Name</label>
                        <div class="controls">
                            <input name="fist_name" type="text"  placeholder="First_name" value="<?php echo !empty($first_name)?$first_name:'';?>">
                            <?php if (!empty($fisrt_nameError)): ?>
                                <span class="help-inline"><?php echo $fisrt_nameError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($last_nameError)?'error':'';?>">
                        <label class="control-label">Last Name</label>
                        <div class="controls">
                            <input name="last_name" type="text"  placeholder="Last_name" value="<?php echo !empty($last_name)?$last_name:'';?>">
                            <?php if (!empty($last_nameError)): ?>
                                <span class="help-inline"><?php echo $last_nameError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($buildingError)?'error':'';?>">
                        <label class="control-label">Building</label>
                        <div class="controls">
                            <input name="building" type="text" placeholder="Building" value="<?php echo !empty($building)?$building:'';?>">
                            <?php if (!empty($buildingError)): ?>
                                <span class="help-inline"><?php echo $buildingError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($phoneError)?'error':'';?>">
                        <label class="control-label">Phone</label>
                        <div class="controls">
                            <input name="phone" type="text"  placeholder="Phone" value="<?php echo !empty($phone)?$phone:'';?>">
                            <?php if (!empty($phoneError)): ?>
                                <span class="help-inline"><?php echo $phoneError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($qosError)?'error':'';?>">
                        <label class="control-label">QOS</label>
                        <div class="controls">
                            <input name="qos" type="text"  placeholder="Qos" value="<?php echo !empty($qos)?$q:'';?>">
                            <?php if (!empty($qosError)): ?>
                                <span class="help-inline"><?php echo $qosError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($salesrror)?'error':'';?>">
                        <label class="control-label">Sales</label>
                        <div class="controls">
                            <input name="sales" type="text" placeholder="Sales" value="<?php echo !empty($sales)?$sales:'';?>">
                            <?php if (!empty($salesrror)): ?>
                                <span class="help-inline"><?php echo $salesrror;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($usernameError)?'error':'';?>">
                        <label class="control-label">Username/label>
                        <div class="controls">
                            <input name="username" type="text"  placeholder="Username" value="<?php echo !empty($username)?$username:'';?>">
                            <?php if (!empty($usernameError)): ?>
                                <span class="help-inline"><?php echo $usernameError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="form-actions">
                          <button type="submit" class="btn btn-success">Create</button>
                          <a class="btn" href="index.php">Back</a>
                        </div>
                    </form>
                </div>

    </div> <!-- /container -->
  </body>
</html>

Lines 40-67 — you do not close your if's.
Line 186: I don't see a problem.
Might be a good idea to share the error with us.

Thank you matrixdevuk,
i'm still having a problem

this is my database:

CREATE TABLE  `customers` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`location` VARCHAR( 100 ) NOT NULL ,
`date` VARCHAR( 100 ) NOT NULL ,
`first_name` VARCHAR( 100 ) NOT NULL,
`last_name` VARCHAR( 100 ) NOT NULL ,
`building` VARCHAR( 100 ) NOT NULL ,
`phone` VARCHAR( 100 ) NOT NULL,
`qos` VARCHAR( 100 ) NOT NULL ,
`sales` VARCHAR( 100 ) NOT NULL ,
`username` VARCHAR( 100 ) NOT NULL
) ENGINE = INNODB;

this is my crete.php file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link   href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.min.js"></script>
</head>

<body>
    <div class="container">
            <div class="row">
                <h3>DSN Sales</h3>
            </div>
            <div class="row">
                <p>
                    <a href="create.php" class="btn btn-success">Create</a>
                </p>

                <table class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>Location</th>
                          <th>Date</th>
                          <th>First Name</th>
                          <th>Last Name</th>
                          <th>Building Number</th>
                          <th>Phone</th>
                          <th>Qos</th>
                          <th>Sales</th>
                          <th>First Name</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                      <?php 
                       include 'database.php';
                       $pdo = Database::connect();
                       $sql = 'SELECT * FROM customers ORDER BY id DESC';
                       foreach ($pdo->query($sql) as $row) {
                                echo '<tr>';
                                echo '<td>'. $row['location'] . '</td>';
                                echo '<td>'. $row['date'] . '</td>';
                                echo '<td>'. $row['first_name'] . '</td>';
                                echo '<td>'. $row['last_name'] . '</td>';
                                echo '<td>'. $row['building'] . '</td>';
                                echo '<td>'. $row['phone'] . '</td>';
                                echo '<td>'. $row['qos'] . '</td>';
                                echo '<td>'. $row['sales'] . '</td>';
                                echo '<td>'. $row['username'] . '</td>';
                                echo '<td width=250>';
                                echo '<a class="btn" href="read.php?id='.$row['id'].'">Read</a>';
                                echo '&nbsp;';
                                echo '<a class="btn btn-success" href="update.php?id='.$row['id'].'">Update</a>';
                                echo '&nbsp;';
                                echo '<a class="btn btn-danger" href="delete.php?id='.$row['id'].'">Delete</a>';
                                echo '</td>';
                                echo '</tr>';
                       }
                       Database::disconnect();
                      ?>
                      </tbody>
                </table>
        </div>
    </div> <!-- /container -->
  </body>
</html>

and when i i fill the fields this is the error i get.

sorry the previous code is my index.php class.
Here it is my create.php class code

<?php 

    require 'database.php';

    if ( !empty($_POST)) {
        // keep track validation errors
        $locationError = null;
        $dateError = null;
        $fisrt_nameError = null;
        $last_nameError = null;
        $buildingError = null;
        $phoneError = null;
        $qosError = null;
        $salesrror = null;
        $usernameError = null;

        // keep track post values

        $location = $_POST['location'];
        $date = $_POST['date'];
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $building = $_POST['building'];
        $phone = $_POST['phone'];
        $qos = $_POST['qos'];
        $sales = $_POST['sales'];
        $username = $_POST['username'];

        // validate input
        $valid = true;

        if (empty($location)) 
        {
            $locationError = 'Please enter Location';
            $valid = false;
        }
        if (empty($date)) 
        {
            $dateError = 'Please enter Valid Date';
            $valid = false;

        }
        if (empty($first_name)) 
        {
            $fisrt_nameError = 'Please enter First Name';
            $valid = false;
        }
        if (empty($last_name)) 
        {
            $last_nameError = 'Please enter Last Name';
            $valid = false;
        }
        if (empty($building)) 
        {
            $buildingError = 'Please enter Building Number';
            $valid = false;
        }
        if (empty($phone)) 
        {
            $phoneError = 'Please enter Phone Number';
            $valid = false;
        }
        if (empty($qos)) 
        {
            $qosError = 'Please enter Qos';
            $valid = false;
        }
        if (empty($sales)) 
        {
            $salesrror = 'Please enter Sales Person Name';
            $valid = false;
        }
        if (empty($username)) 
        {
            $usernameError = 'Please enter customer Username';
            $valid = false;
        }
        // insert data
        if ($valid) {
            $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "INSERT INTO customers (location,date,first_name,last_name,building,phone,qos,sales,username) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
            $q = $pdo->prepare($sql);
            $q->execute(array($location,$date,$first_name,$last_name,$building,$phone,$qos,$sales,$username));
            Database::disconnect();
            header("Location: index.php");
        }
    }
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link   href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">

                <div class="span10 offset1">
                    <div class="row">
                        <center><h3>Create a Customer</h3></center>
                    </div>

                    <form class="form-horizontal" action="create.php" method="post">

                      <div class="control-group <?php echo !empty($locationError)?'error':'';?>">
                        <label class="control-label">Location:</label>
                        <div class="controls">
                            <input name="location" type="text"  placeholder="Location" value="<?php echo !empty($location)?$location:'';?>">
                            <?php if (!empty($locationError)): ?>
                                <span class="help-inline"><?php echo $locationError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($dateError)?'error':'';?>">
                        <label class="control-label">Date:</label>
                        <div class="controls">
                            <input name="date" type="text" placeholder="Date" value="<?php echo !empty($date)?$date:'';?>">
                            <?php if (!empty($dateError)): ?>
                                <span class="help-inline"><?php echo $dateError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($fisrt_nameError)?'error':'';?>">
                        <label class="control-label">First Name</label>
                        <div class="controls">
                            <input name="fist_name" type="text"  placeholder="First_name" value="<?php echo !empty($first_name)?$first_name:'';?>">
                            <?php if (!empty($fisrt_nameError)): ?>
                                <span class="help-inline"><?php echo $fisrt_nameError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($last_nameError)?'error':'';?>">
                        <label class="control-label">Last Name</label>
                        <div class="controls">
                            <input name="last_name" type="text"  placeholder="Last_name" value="<?php echo !empty($last_name)?$last_name:'';?>">
                            <?php if (!empty($last_nameError)): ?>
                                <span class="help-inline"><?php echo $last_nameError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($buildingError)?'error':'';?>">
                        <label class="control-label">Building</label>
                        <div class="controls">
                            <input name="building" type="text" placeholder="Building" value="<?php echo !empty($building)?$building:'';?>">
                            <?php if (!empty($buildingError)): ?>
                                <span class="help-inline"><?php echo $buildingError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($phoneError)?'error':'';?>">
                        <label class="control-label">Phone</label>
                        <div class="controls">
                            <input name="phone" type="text"  placeholder="Phone" value="<?php echo !empty($phone)?$phone:'';?>">
                            <?php if (!empty($phoneError)): ?>
                                <span class="help-inline"><?php echo $phoneError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($qosError)?'error':'';?>">
                        <label class="control-label">QOS</label>
                        <div class="controls">
                            <input name="qos" type="text"  placeholder="Qos" value="<?php echo !empty($qos)?$q:'';?>">
                            <?php if (!empty($qosError)): ?>
                                <span class="help-inline"><?php echo $qosError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($salesrror)?'error':'';?>">
                        <label class="control-label">Sales</label>
                        <div class="controls">
                            <input name="sales" type="text" placeholder="Sales" value="<?php echo !empty($sales)?$sales:'';?>">
                            <?php if (!empty($salesrror)): ?>
                                <span class="help-inline"><?php echo $salesrror;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="control-group <?php echo !empty($usernameError)?'error':'';?>">
                        <label class="control-label">Username</label>
                        <div class="controls">
                            <input name="username" type="text"  placeholder="Username" value="<?php echo !empty($username)?$username:'';?>">
                            <?php if (!empty($usernameError)): ?>
                                <span class="help-inline"><?php echo $usernameError;?></span>
                            <?php endif;?>
                        </div>
                      </div>

                      <div class="form-actions">
                          <button type="submit" class="btn btn-success">Create</button>
                          <a class="btn" href="index.php">Back</a>
                        </div>

                    </form>


                </div>

    </div> <!-- /container -->
  </body>
</html>

thank you.......

For the first name, you messed up your input's name. You did name="fist_name".

Thank you very much, the problem is fixed, but let me ask you do you have any tool or anything how come you found the error as easily...

thank you very much

Got it, just keep it up body thank's.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.