Here is the file, I am facing this issue Warning: Array to string conversion in C:\xampp\htdocs\backhaul-dispatcher\login\process.php on line 46 Warning: Array to string conversion in C:\xampp\htdocs\backhaul-dispatcher\login\process.php on line 46 Warning: Array to string conversion in C:\xampp\htdocs\backhaul-dispatcher\login\process.php on line 46 Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\backhaul-dispatcher\login\process.php:46 Stack trace: #0 C:\xampp\htdocs\backhaul-dispatcher\login\process.php(46): PDOStatement->execute(Array) #1 {main} thrown in C:\x ampp\htdocs\backhaul-dispatcher\login\process.php on line 46
<?php
require_once('config.php');
session_start();
if (!isset($_SESSION['userlogin'])) {
header("location: login.php");
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION);
header("Location: login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1-rc.1/css/select2.min.css'>
<link rel="stylesheet" href="css/prospect.css">
<title>Add New prospect | BackHaul Dispatcher</title>
</head>
<body>
<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-light">
<div class="container-fluid ">
<a class="navbar-brand" href="#">BackHaul Dispatcher</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="add-new-prospect.php">Add New prospect</a>
</li>
<li class="nav-item">
<a class="nav-link" href="prospect-details.php">prospect Details</a>
</li>
<li class="nav-item">
<a class="nav-link" href="index.php?logout=true">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<form action="add-new-prospect.php" method="post">
<div class="container row g-3">
<div class="col-md-4 pt-5 ps-2 pe-2 ">
<label for="client_first_name" class="form-label">First Name</label>
<input type="text" class="form-control" id="client_first_name" name="client_first_name">
</div>
<div class="col-md-4 pt-5 ps-2 pe-2 ">
<label for="client_last_name" class="form-label">Last Name</label>
<input type="text" class="form-control" id="client_last_name" name="lient_last_name">
</div>
<div class="col-md-4 pt-5 ps-2 pe-2 ">
<label for="phone_number" class="form-label">Phone Number</label>
<input type="text" class="form-control" id="phone_number" name="phone_number">
</div>
<div class="col-md-6 pt-2 ps-2 pe-2 ">
<label for="client_email" class="form-label">Email</label>
<input type="email" class="form-control" id="client_email" name="client_email">
</div>
<div class="col-md-6 pt-2 ps-2 pe-2 ">
<label for="client_address" class="form-label">Address</label>
<input type="text" class="form-control" id="client_address" name="client_address" placeholder="city, state, or zip code">
</div>
<div class="col-md-6 pt-2 ps-2 pe-2 ">
<label for="mc_number" class="form-label">M.C Number</label>
<input type="text" class="form-control" id="mc_number" name="mc_number">
</div>
<div class="col-md-6 pt-2 ps-2 pe-2 ">
<label for="speciality" class="form-label">Speciality</label>
<input type="text" class="form-control" id="speciality" name="speciality">
</div>
<div class="form-group col-md-6 pt-2 ps-2 pe-2 ">
<label for="where_haul">Where do you Haul?</label>
<select class="form-control form-select" id="where_haul" name="where_haul">
<option value="interstate">Intersate</option>
<option value="intrastate">Intrastate</option>
<option value="usa_ca">USA/CA</option>
</select>
</div>
<div class="form-group col-md-6 pt-2 ps-2 pe-2 " id="interstate">
<label for="interstate_option">Intersate</label>
<select class="form-control form-select select-multiple" multiple="multiple" id="interstate_option" name="interstate_option">
<option value="state" selected disabled>Select state</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
</select>
</div>
<div class="form-group col-md-6 pt-2 ps-2 pe-2 " id="intrastate">
<label for="intrastate_option">Intrastate</label>
<select class="form-control form-select select-multiple" multiple="multiple" id="intrastate_option" name="intrastate_option">
<option value="state" selected >Select state</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
</select>
</div>
<div class="form-group col-md-6 pt-2 ps-2 pe-2 " id="usa_ca">
<label for="usa_ca_option">USA/CA</label>
<select class="form-control form-select select-multiple" multiple="multiple" id="usa_ca_option" name="usa_ca_option">
<option value="state" selected>Select state</option>
<option value="AL">Alabama</option>
</select>
</div>
<div class="col-md-6 pt-2 ps-2 pe-2 ">
<label for="equipment" class="form-label">Equipment</label>
<select id="equipment" name="equipment" class="form-select">
<optgroup label="Trailer Type">
<option value="dry-van" selected>Dry Van</option>
<option value="reefer">Reefer</option>
<option value="double-drop">Double Drop</option>
<option value="lowboy">Lowboy</option>
<option value="step-dack">Step-Dack</option>
<option value="hotshot">Hotshot</option>
<option value="flat-bed">Flat-Bed</option>
</optgroup>
<optgroup label="Box Truck">
<option value="straight-box-truck">Straight</option>
<option value="reefer-box-truck">Reefer</option>
</optgroup>
<optgroup label="Power Only">
<option value="xl">XL</option>
<option value="xxl">XXL</option>
<option value="xxxl">XXXL</option>
</optgroup>
</select>
</div>
<div class="col-md-6 pt-2 ps-2 pe-2 ">
<label for="solo_team" class="form-label">Do you drive Solo or team?</label>
<select id="solo_team" name="solo_team" class="form-select">
<option value="solo">Solo</option>
<option value="team">Team</option>
</select>
</div>
<p class="pt-2 ps-2 pe-2 ">Other Equipment</p>
<div class="form-check col-md-2 pt-2 ps-5 pe-2 ">
<input class="form-check-input" type="checkbox" value="" id="chain" name="chain" checked>
<label class="form-check-label" for="chain">
Chain
</label>
</div>
<div class="form-check col-md-2 pt-2 ps-5 pe-2 ">
<input class="form-check-input" type="checkbox" value="" id="lift_gate" name="lift_gate">
<label class="form-check-label" for="lift_gate">
Lift Gate
</label>
</div>
<div class="form-check col-md-2 pt-2 ps-5 pe-2 ">
<input class="form-check-input" type="checkbox" value="" id="swing_doors" name="swing_doors">
<label class="form-check-label" for="swing_doors">
Swing Doors
</label>
</div>
<div class="form-check col-md-2 pt-2 ps-5 pe-2 ">
<input class="form-check-input" type="checkbox" value="" id="blanket" name="blanket">
<label class="form-check-label" for="blanket">
Blanket
</label>
</div>
<div class="form-check col-md-2 pt-2 ps-5 pe-2 ">
<input class="form-check-input" type="checkbox" value="" id="wooden_floor" name="wooden_floor">
<label class="form-check-label" for="wooden_floor">
Wooden Floor
</label>
</div>
<div class="form-check col-md-2 pt-2 ps-5 pe-2 ">
<input class="form-check-input" type="checkbox" value="" id="ramp" name="ramp">
<label class="form-check-label" for="ramp">
Ramp
</label>
</div>
<div class="form-check col-md-4 pt-2 ps-5 pe-2 ">
<input class="form-check-input" type="checkbox" value="" id="dock_high" name="dock_high">
<label class="form-check-label" for="dock_high">
Dock High
</label>
</div>
<div class="col-md-4 pt-2 ps-2 pe-2 ">
<label for="no_drivers" class="form-label">No. of Drivers</label>
<input type="number" class="form-control" id="no_drivers" name="no_drivers">
</div>
<div class="col-md-4 pt-2 ps-2 pe-2 ">
<label for="no_power_units" class="form-label">No. of Power Units</label>
<input type="number" class="form-control" id="no_power_units" name="no_power_units">
</div>
<div class="col-md-4 pt-2 ps-2 pe-2 ">
<label for="no_trailer" class="form-label">No. of Trailer</label>
<input type="number" class="form-control" id="no_trailer" name="no_trailer">
</div>
<div class="col-md-4 pt-2 ps-2 pe-2 ">
<label for="length_trailer" class="form-label">Length of trailer</label>
<input type="text" class="form-control" id="length_trailer" name="length_trailer" placeholder="Feet">
</div>
<div class="col-md-4 pt-2 ps-2 pe-2 ">
<label for="min_weight" class="form-label">Min. Weight</label>
<input type="text" class="form-control" id="min_weight" name="min_weight" placeholder="lbs">
</div>
<div class="col-md-4 pt-2 ps-2 pe-2 ">
<label for="max_weight" class="form-label">Max. Weight</label>
<input type="text" class="form-control" id="max_weight" name="max_weight" placeholder="lbs">
</div>
<div class="col-12 pt-3 ps-2 pe-2 pb-5">
<input class="btn btn-primary" type="submit" id="submit" name="submit" value="Submit">
</div>
</div>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1-rc.1/js/select2.min.js'></script>
<script type="text/javascript">
$(function() {
$('#submit').click(function(e) {
var valid = this.form.checkValidity();
if (valid) {
var client_first_name = $('#client_first_name').val();
var client_last_name = $('#client_last_name').val();
var client_email = $('#client_email').val();
var phone_number = $('#phone_number').val();
var client_address = $('#client_address').val();
var mc_number = $('#mc_number').val();
var speciality = $('#speciality').val();
var where_haul = $('#where_haul').val();
var interstate_option = $('#interstate_option').val();
var intrastate_option = $('#intrastate_option').val();
var usa_ca_option = $('#usa_ca_option').val();
var equipment = $('#equipment').val();
var solo_team = $('#solo_team').val();
var chain = $('#chain').val();
var tarps = $('#tarps').val();
var binders = $('#binders').val();
var pallet_jack = $('#pallet_jack').val();
var air_ride = $('#air_ride').val();
var hazmat = $('#hazmat').val();
var sides = $('#sides').val();
var coil_rack = $('#coil_rack').val();
var load_bar = $('#load_bar').val();
var dunnage = $('#dunnage').val();
var lift_gate = $('#lift_gate').val();
var swing_doors = $('#swing_doors').val();
var blanket = $('#blanket').val();
var wooden_floor = $('#wooden_floor').val();
var ramp = $('#ramp').val();
var dock_high = $('#dock_high').val();
var no_drivers = $('#no_drivers').val();
var no_power_units = $('#no_power_units').val();
var no_trailer = $('#no_trailer').val();
var length_trailer = $('#length_trailer').val();
var min_weight = $('#min_weight').val();
var max_weight = $('#max_weight').val();
e.preventDefault();
$.ajax({
type: 'POST',
url: 'process.php',
data: {
client_first_name: client_first_name,
client_last_name: client_last_name,
client_email: client_email,
phone_number: phone_number,
client_address: client_address,
mc_number: mc_number,
speciality: speciality,
where_haul: where_haul,
interstate_option: interstate_option,
intrastate_option: intrastate_option,
usa_ca_option: usa_ca_option,
equipment: equipment,
solo_team: solo_team,
chain: chain,
tarps: tarps,
pallet_jack: pallet_jack,
binders: binders,
air_ride: air_ride,
hazmat: hazmat,
sides: sides,
coil_rack: coil_rack,
load_bar: load_bar,
dunnage: dunnage,
lift_gate: lift_gate,
swing_doors: swing_doors,
blanket: blanket,
wooden_floor: wooden_floor,
ramp: ramp,
dock_high: dock_high,
no_drivers: no_drivers,
no_power_units: no_power_units,
no_trailer: no_trailer,
length_trailer: length_trailer,
min_weight: min_weight,
max_weight: max_weight
},
success: function(data) {
Swal.fire({
'title': 'Successful',
'text': data,
'type': 'success'
})
},
error: function(data) {
Swal.fire({
'title': 'Errors',
'text': 'There were error while saving data.',
'type': 'error'
})
}
});
} else {
}
});
});
</script>
<script src="main.js"></script>
</body>
</html>
and config.php file
<?php
$db_user ="root";
$db_pass ="";
$db_name ="registration";
$db = new PDO('mysql:host=localhost;dbname=' . $db_name . ';charset=utf8', $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
and process.php file
<?php
require_once('config.php');
if (isset($_POST)) {
$client_first_name = $_POST['client_first_name'];
$client_last_name = $_POST['client_last_name'];
$client_email = $_POST['client_email'];
$phone_number = $_POST['phone_number'];
$client_address = $_POST['client_address'];
$mc_number = $_POST['mc_number'];
$speciality = $_POST['speciality'];
$where_haul = $_POST['where_haul'];
$interstate_option = $_POST['interstate_option'];
$intrastate_option = $_POST['intrastate_option'];
$usa_ca_option = $_POST['usa_ca_option'];
$equipment = $_POST['equipment'];
$solo_team = $_POST['solo_team'];
$chain = $_POST['chain'];
$tarps = $_POST['tarps'];
$binders = $_POST['binders'];
$pallet_jack = $_POST['pallet_jack'];
$air_ride = $_POST['air_ride'];
$hazmat = $_POST['hazmat'];
$sides = $_POST['sides'];
$coil_rack = $_POST['coil_rack'];
$load_bar = $_POST['load_bar'];
$dunnage = $_POST['dunnage'];
$lift_gate = $_POST['lift_gate'];
$swing_doors = $_POST['swing_doors'];
$blanket = $_POST['blanket'];
$wooden_floor = $_POST['wooden_floor'];
$ramp = $_POST['ramp'];
$dock_high = $_POST['dock_high'];
$no_drivers = $_POST['no_drivers'];
$no_power_units = $_POST['no_power_units'];
$no_trailer = $_POST['no_trailer'];
$length_trailer = $_POST['length_trailer'];
$min_weight = $_POST['min_weight'];
$max_weight = $_POST['max_weight'];
// $authority_letter = $_POST['authority_letter'];
// $w9 = $_POST['w9'];
// $certificate_insurance = $_POST['certificate_insurance'];
// $other_files = $_POST['other_files'];
$sql = "INSERT INTO prospects (client_first_name,client_last_name,client_email,phone_number,client_address,mc_number,speciality,where_haul,interstate_option,intrastate_option,usa_ca_option,equipment,solo_team,chain,tarps,binders,pallet_jack,air_ride,hazmat,sides,coil_rack,load_bar,dunnage,lift_gate,swing_doors,blanket,wooden_floor,ramp,dock_high,no_drivers,no_power_units,no_trailer,length_trailer,min_weight,max_weight) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmtinsert = $db->prepare($sql);
/** LINE 46 **/ $result = $stmtinsert->execute([$client_first_name, $client_last_name, $client_email, $phone_number, $client_address, $mc_number, $speciality, $where_haul, $interstate_option, $intrastate_option, $usa_ca_option, $equipment, $solo_team, $chain, $tarps, $binders, $pallet_jack, $air_ride, $hazmat, $sides, $coil_rack, $load_bar, $dunnage, $lift_gate, $swing_doors, $blanket, $wooden_floor, $ramp, $dock_high, $no_drivers, $no_power_units, $no_trailer, $length_trailer, $min_weight, $max_weight]);
if ($result) {
echo 'Successfully Submitted';
} else {
echo 'There were error while saving data.';
}
} else {
echo 'No Data';
}
You have select inputs allowing multiple values (exe: "interstate_option"), so in your PHP script $_POST['interstate_option'] is a array. You'r passing the value of $_POST['interstate_option'] to the PDO, wich is expecting a string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.