Reputation: 1
I have a problem with my code it shows
count(): Parameter must be an array or an object that implements Countable and Uninitialized string offset: 0
$site = $_POST['site'];
$url = $_POST['url'];
$query = '';
for($count = 0; $count<count($site); $count++){
$site_name = mysqli_real_escape_string($con, $site[$count]);
$url_name = mysqli_real_escape_string($con, $url[$count]);
if($site_name != '' && $url_name != ''){
$query .='INSERT INTO `url` (`site`, `http`) VALUES ("'.$site_name.'", "'.$url_name.'")';
}
}
The expected out is to insert data into the database
Upvotes: 0
Views: 73
Reputation: 2767
Make sure $_POST['site']
is an array that can implement Countable
$site = $_POST['site'] ?? []; // php 7
$site = is_array($_POST['site']) ? $_POST['site'] : [] // php <7
Upvotes: 1
Reputation: 59
your $site variable is not countable, use var_dump($site) to see it's value and type
Upvotes: 0