Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查询不起作用_Php_Html_Mysql_Sql_Foreach - Fatal编程技术网

Php 查询不起作用

Php 查询不起作用,php,html,mysql,sql,foreach,Php,Html,Mysql,Sql,Foreach,我制定了以下代码: Acum, bifeaza materiile pe care le studiaza clasa aleasa:<br /> <form name="servForm" action="<?php $PHP_SELF; ?>" method="post" > <table border="0"> <?php $a = 0; $rezultat = "SELECT id, ma

我制定了以下代码:

  Acum, bifeaza materiile pe care le studiaza clasa aleasa:<br />
     <form name="servForm" action="<?php $PHP_SELF; ?>" method="post" >
    <table border="0">
  <?php  
$a = 0;
        $rezultat = "SELECT id, materie
        FROM  materii
        ORDER BY id";

        $rezultat1 = mysql_query($rezultat);
        while($plm = mysql_fetch_array($rezultat1))
            {
            if($a++ %5 == 0) echo "<tr>";
            ?>
 <td align="center"><input type="checkbox" name="checkbox2[]" value="<?php echo $plm['id']; ?>" /></td>
            <td style="text-align:left"><?php echo $plm["materie"]; ?>&nbsp;</td>
        <?php
        if($a %5 == 0) echo "</tr>";
            }
        ?>
    </table>
</div>
<br/>

    <input type="reset" value="Sterge" /> <input type="submit" value="Salveaza" name="savebtn" />
    </form>


    <?php
    if(isset($_POST['savebtn']))
    {
     foreach($_POST["checkbox2"] as $loc_id)
{
  $query = "INSERT INTO materii_pe_clase(id_scoala,id_clasa,id_materie) VALUES('$scoalalui','$clasalui','$loc_id')"; //aici cauta ! :)) 
  $result5 = mysql_query($query)
  or die('eroare');

}//sfarsit foreact
     }//sfarsit if isset

这里的问题是,您关闭了错误工具,因为PHP应该这样说。
注意:未定义变量$PHP\u SELF”

既然你看不到,我想,这是你“问题”的根源

PHP\u SELF
不是一个变量,而是一个常量。这里甚至不需要它,因为默认情况下,PHP将数据发送到其目标URL

我提高了你的代码的可读性,所以现在应该对你有用了

<?php

// You want to see all errors? Fine:
error_reporting(E_ALL);

$a = 0;
$rezultat = "SELECT id, materie FROM  materii ORDER BY id";
$rezultat1 = mysql_query($rezultat);


// If the form is submitted, this will be executed
if (isset($_POST['savebtn'])) {
    foreach($_POST["checkbox2"] as $loc_id) {

        $query = "INSERT INTO `materii_pe_clase` (`id_scoala`, `id_clasa`, `id_materie`) VALUES('$scoalalui', '$clasalui', '$loc_id')"; 

        $result = mysql_unbuffered_query($query);

        if (!$result){
            die(mysql_error());
        }
    }

    // And finally
    die('Saved. Thanks');
}
?>

 Acum, bifeaza materiile pe care le studiaza clasa aleasa: <br />

 <form name="servForm" method="POST">
    <table border="0">
        <?php while($plm = mysql_fetch_array($rezultat1)) : ?>

        <?php if ($a++ %5 == 0) :?>
        <tr>
        <?php endif; ?>

            <td align="center">
                <input type="checkbox" name="checkbox2[]" value="<?php echo $plm['id']; ?>" />
            </td>
            <td style="text-align:left"><?php echo $plm["materie"]; ?>&nbsp;</td>

        <?php if($a %5 == 0) : ?>
        </tr>
        <?php endif; ?>

        <?php endwhile; ?>

    </table>

    <br/>

    <input type="reset" value="Sterge" />
    <input type="submit" value="Salveaza" name="savebtn" />
 </form>

什么不起作用?错误消息、日志条目等。请定义“不起作用”“。如果出现错误,请发布该错误。如果它执行,请说明结果与您的期望有何不同。它不会将值添加到数据库中。没有发生任何事情,它只是将我的页面返回到此表单的第一步。什么也没发生。没有错误,nothing@Fred,他在问题中提到了这一点。@JamieTaylor Yea刚刚注意到,略过了最后一点。
<?php

// You want to see all errors? Fine:
error_reporting(E_ALL);

$a = 0;
$rezultat = "SELECT id, materie FROM  materii ORDER BY id";
$rezultat1 = mysql_query($rezultat);


// If the form is submitted, this will be executed
if (isset($_POST['savebtn'])) {
    foreach($_POST["checkbox2"] as $loc_id) {

        $query = "INSERT INTO `materii_pe_clase` (`id_scoala`, `id_clasa`, `id_materie`) VALUES('$scoalalui', '$clasalui', '$loc_id')"; 

        $result = mysql_unbuffered_query($query);

        if (!$result){
            die(mysql_error());
        }
    }

    // And finally
    die('Saved. Thanks');
}
?>

 Acum, bifeaza materiile pe care le studiaza clasa aleasa: <br />

 <form name="servForm" method="POST">
    <table border="0">
        <?php while($plm = mysql_fetch_array($rezultat1)) : ?>

        <?php if ($a++ %5 == 0) :?>
        <tr>
        <?php endif; ?>

            <td align="center">
                <input type="checkbox" name="checkbox2[]" value="<?php echo $plm['id']; ?>" />
            </td>
            <td style="text-align:left"><?php echo $plm["materie"]; ?>&nbsp;</td>

        <?php if($a %5 == 0) : ?>
        </tr>
        <?php endif; ?>

        <?php endwhile; ?>

    </table>

    <br/>

    <input type="reset" value="Sterge" />
    <input type="submit" value="Salveaza" name="savebtn" />
 </form>