I'm trying to change the url path by submited form...
index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php include 'file.php'; ?>
<form action=<?php action(); ?> method="post">
<fieldset>
<legend>Choose ID by select tag</legend>
<label>ID:</label>
<select name="id" onchange="this.form.submit()">
<?php option(); ?>
</select>
<label><?php selcet(); ?></label>
</fieldset>
</form>
</body>
</html>
file.php
<?php
function action() {
$value = $_SERVER['PHP_SELF'];
if (isset($_POST['id'])) {
$value .= '?id=' . $_POST['id'];
}
echo $value;
}
function option() {
$count = 3;
for ($i = 1; $i <= $count; $i++) {
$value = 1;
if (isset($_POST['id'])) {
$value = $_POST['id'];
}
if ($i == $value) {
echo '<option value="' . $i . '" selected>' . $i . '</option>';
}
else {
echo '<option value="' . $i . '">' . $i . '</option>';
}
}
}
function selcet() {
$value = 1;
if (isset($_POST['id'])) {
$value = $_POST['id'];
}
echo 'Option ' . $value . ' selected.';
}
?>
the action() function not working as well, I'm getting wrong ids, I want to get ?id=2 while '2' selected.
Can someone help me please? Thanks! :)