$mysqli = new mysqli($server, $username, $password, $database); // Исправьте имя базы данных
$result = $mysqli->query("SELECT tag FROM main");
$tag = $result->fetch_assoc()['tag']; // Извлечение значения
$result = $mysqli->query("SELECT COUNT(tag) as count FROM main");
$val = $result->fetch_assoc()['count'] + 1; // Получение количества и добавление 1
$stmt = $mysqli->prepare("INSERT INTO main(tag, val) VALUES (?, ?)");
$stmt->bind_param("si", $tag, $val);
$stmt->execute();
$mysqli = new mysqli($server, $username, $password);
if ($mysqli ->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
$stmt = $mysqli->prepare("INSERT INTO main(tag, val) VALUES (?, ?)");
$tag = $mysqli->query("SELECT tag FROM main");
$val = $mysqli->query("SELECT val FROM main");
$val = $val + 1;
$stmt->bind_param("si", $tag, $val);
$stmt->execute();
$stmt->close();
$mysqli->close();
Попробуй этот код