shopping.php
<html>
<head>
<?php
if(isset($_POST['sub'])){
$a=$_POST['prod'];
$b=$_POST['qty'];
$_SESSION[$a]=$b;
}
?>
</head>
<body>
<form method="post" action="Billing.php">
Select any Product:
<select name="prod">
<option>Nokia</option>
<option>Reliance</option>
<option>Samsung</option>
<option>LG</option>
</select>
<br><br>
Quantity:<input name="qty"> <br><br>
<input type="submit" name="sub" value="ADD">
</form>
</body></html>
Billing.php
<html>
<head>
<?php
session_start();
echo session_id();
echo "<br>";
echo "selected products are:<br>";
// print_r($_SESSION);
foreach($_SESSION as $x=>$y){
echo "product is $x and Quantity is:$y<br>";
}
?>
</head> </html>
出力
Warning: session_start() [function.session-start]: Cannot send session cookie -
headers already sent by (output started at E:\PHP programs\Billing.php:2) in E:\PHP programs\Billing.php on line 4
Warning: session_start() [function.session-start]: Cannot send session cache limiter -
headers already sent (output started at E:\PHP programs\Billing.php:2) in E:\PHP programs\Billing.php on line 4
上記の警告メッセージの解決策を教えてください。プログラムを正常に実行するにはどうすればよいですか?