php和html中的复选框相关问题

时间:2014-03-25 16:56:53

标签: php

我想打印复选框值(仅选定值),但会显示以下错误 禁止访问!

您无权访问所请求的对象。它受读保护或服务器无法读取。

如果您认为这是服务器错误,请与网站管理员联系。

错误403

本地主机 Apache / 2.4.7(Win32)OpenSSL / 1.0.1e PHP / 5.5.9 这里是整个php文件...我是php的新手...所以请检查我的代码......可能会有一些错误......

<?php // File: anyco.php
    require('anyco_ui.inc.php');
    // Create a database connection
    $conn = oci_connect('system','123','localhost/orcl');
    ui_print_header('FoodItemList');

    //session_start();
    //$cid=$_SESSION['cid'];
                   do_query($conn, 'SELECT Fooditem_ID,Food_item_name,price,day_available,time_available,discount_percentage,start_date,deadline FROM Food_Item');
                   ui_print_footer(date('Y-m-d H:i:s'));
    // Execute query and display results
    function do_query($conn, $query)
    {
            $stid = oci_parse($conn, $query);
            $r = oci_execute($stid,OCI_DEFAULT);
            print '<table border="1">';
            print '<tr>';
            print '<td>Food_ID<td>Food_Name<td>Price(tk)<td>Dvailable_day<td>Avaliable_time<td>Discount<td>Dis_start date<td>Dis_finish date<td>selected item<td>quanity';
            while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) 
            {
                print '<tr>';
                $num=1;
                $val="";
                foreach ($row as $item) 
                {                  
                    if($num==1)
                    { 
                       $val = $item;
                       $num=2;
                    }

                    print '<td>'.($item!== null ? htmlentities($item) : '&nbsp;').'</td>';

                }

                echo '<td><input type="checkbox" name="ticked[]" value="$val"></td>';
                echo '<td><input type="number" name ="name[]" ></td>';
                print '</tr>';
           }

       print '</table>';
    } 

    if(isset($_POST['submit'])&&)
    {
              echo'yeeeeeeeeeeeeeeee';
             $ticked = $_POST['ticked'];
             foreach ($ticked as $ticked=>$value) 
             {
                 echo "values selected are : ".$value."<br />";
             }
    }

?>
<html>
<style>
body
{
background:orange;
}
</style>
<body text="green">
<br><br>
<form action="<?php echo $current_file;?>" method="POST">


    <input type ="submit" value="Submit"><br><br>   
</form>



</body>
</html>

1 个答案:

答案 0 :(得分:0)

首先要做的是删除&&

if(isset($_POST['submit'])&&)
                          ^ remove the &&

然后改变这个

<input type ="submit" value="Submit"><br><br>   

<input type="submit" name="submit" value="Submit"><br><br>   

因为isset($_POST['submit'])正在寻找name=""

<?php
if(isset($_POST['submit']))
{
    echo'yeeeeeeeeeeeeeeee';

    // more of your code...
}
?>

修改

除去

action="<?php echo $current_file;?>"

<form action="<?php echo $current_file;?>" method="POST">

所以它应该只是

<form method="POST">