Answer the question
In order to leave comments, you need to log in
Notice: Undefined index: languageval. What is the problem?
Hello! I write linked lists with data loading from the database. I am writing from a video tutorial. I don't understand why I get the error "Notice: Undefined index: languageval in /opt/lampp/htdocs/Lesko/select-registration.php on line 5". Because of it, the selection options from the second select are not loaded. How to fix?
Page code with selects:
<?php
require_once "function.php";
if($_POST['languageval']) {
$return = selectCountries();
exit($return);
}
$languages = selectLanguages();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="lists.js"></script>
<style>
form div{margin: 0 0 15px 0;}
#divcountry, #divgenre {display: none;}
</style>
</head>
<body>
<div class="choise">
<form action="" method="post">
<div>
<select name="language" id="language">
<option value="0">выберете язык</option>
<?php foreach ($languages as $language): ?>
<option value="<?=$language['id_language']?>"><?=$language['language']?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<select disabled name="country" id="country">
<option value="0">выберете страну</option>
</select>
</div>
<div>
<select disabled name="genre" id="genre">
<option value="0">выберете жанр</option>
</select>
</div>
</div>
</body>
</html>
/*global $ , jQuery*/
/*jslint browser:true */
$(document).ready(function () {
"use strict";
$("#language").change(function () {
var languageval = parseInt($("#language").val(), 10);
selectCountries(languageval);
});
});
function selectCountries(languageval) {
"use strict";
var country = $("#country");
if (languageval > 0) {
$("#divcountry");
country.attr("disabled", false);
country.load(
"select-registration.php",
{languageval: languageval}
);
}
}
<?php
$GLOBALS['link'] = mysqli_connect("localhost", "root", "", "lesko") or die ("Нет соединения");
mysqli_set_charset($link, 'utf8');
?>
<?php
function selectLanguages () {
$query = "SELECT * FROM languages_";
$res = mysqli_query($GLOBALS['link'], $query);
$languages = array();
while ($row = mysqli_fetch_assoc($res)) {
$languages[] = $row;
}
return $languages;
}
function selectCountries() {
$languageval = (int)$_POST['languageval'];
$query = "SELECT * FROM countries_ WHERE id_language = $languageval";
$res = mysqli_query($query);
$return = "<option value='0'>выберете страну</option>";
while ($row = mysqli_fetch_assoc($res)){
$return .="<option value='{$row['id_country']}'>{$row['country']}</option>";
}
return $return;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question