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>