PHP表单IF问题

时间:2013-11-27 22:09:23

标签: php mysql

好的,所以我在代码的顶部有这个

    require(__DIR__ . "/lib/db.php");
if (!empty($_POST["action"])) {
        if ($_POST["action"] == "addCat") {
            echo "Please wait...";
            $sql1 = "INSERT INTO categories (name) VALUES ('".$_POST["name"]."')";
            if (mysql_query($sql1)) {
                $success = true;
            }
            if (!isset($success)) {
                echo "Error Occured Adding Category!";
            } else {
                echo "Category added!";
            }
        }
        if ($_POST["action"] == "delCat") {
            echo "Please wait...";
            $catNames = $_POST['catName'];
            if(empty($catNames)) {
                return;
            } else {
                $N = count($catNames);
                for($i=0; $i < $N; $i++) {
                    $sql = "DELETE FROM categories WHERE id='$catNames[$i]'";
                    if (mysql_query($sql)) {
                        $success = true;
                    }
                    $sql2 = "SELECT * FROM catrel WHERE categoryID = '$catNames[$i]'";
                    if (mysql_query($sql2)) {
                        mysql_query("DELETE FROM catrel WHERE categoryID = '$catNames[$i]'");
                    }
                }
            }
            if (!isset($success)) {
                echo "Could not delete category! Error Occured!";
            } else {
                echo "Category deleted!";
            }
        }
    }

我在同一页面中有两种不同的表单,隐藏的值会推送addCat或delCat。由于某种原因,似乎SQL没有被解析,但它没有显示任何错误。任何帮助将受到高度赞赏。如果需要,我可以发布整个页面。

0 个答案:

没有答案