Data from radio button to php not work

Discuss coding issues, and scripts related to PHP and MySQL.
mluci12
Posts: 39

Data from radio button to php not work

Code: Select all

<form action="" method="post">
 Type: <select name="studii" id="studii">
  <option value="">---</option>
  <option value="requiment">Requiment</option>
  <option value="Available">Available</option> <br / >
   </select><br />
  Type2 <input type="radio" name="stare_c" id="stare_c1" value="rent" /> Rent
   <input type="radio" name="stare_c" id="stare_c2" value="sell" /> Sell<br />
</form>

Code: Select all

<?php 
$item1 = $_POST['studii'];
$_SESSION["session"]=$item1;
$item2 = $_POST['stare_c1'];
echo '<a href="search.php?idt222='.$item1.'&idk2222='.$item2.'" target="_blank">Search</a>';
?>
Why don't work?

Admin
Hi,
The "name" value of the radio button is "stare_c" (not "stare_c1"), so in php should be:

Code: Select all

$item2 = $_POST['stare_c']; 
- Also, if you use $_SESSION, add session_start(); to the beginning of that php script.

mluci12
Dont work.Why?Have you any other ideea?

Admin
Maybe you need a "submit" button in the <form>.
I tested this code in a php file, and it works.

Code: Select all

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
session_start();

$re_link ='';
if(isset($_POST['studii']) && isset($_POST['stare_c'])){
  $item1 = $_POST['studii'];
  $_SESSION['session']=$item1;
  $item2 = $_POST['stare_c'];
  $re_link = '<a href="search.php?idt222='.$item1.'&idk2222='.$item2.'" target="_blank">Search</a>';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title</title>
</head>
<body>
<?php echo $re_link; ?>
<form action="" method="post">
 Type: <select name="studii" id="studii">
  <option value="">---</option>
  <option value="requiment">Requiment</option>
  <option value="Available">Available</option>
</select><br />
  Type2 <input type="radio" name="stare_c" id="stare_c1" value="rent" /> Rent
   <input type="radio" name="stare_c" id="stare_c2" value="sell" /> Sell<br>
  <input type="submit" value="Submit" />
</form>
</body>
</html>
- Put this code to the beginning of your script to can see if there is any php error.

Code: Select all

ini_set('display_errors',1);
error_reporting(E_ALL); 
And tell exactly what you want to make.

Similar Topics