0

The PHP case statement won't properly show up. Does anyone know why? I tried with and without brackets around the numbers. But the whole page breaks from this code...

    $cat = 226;
    global $wpdb;
    switch ($cat) {
        case "228": // アクセサリー
        case "226": // バッグ
        case "224": // 衣服
        case "231": // 帽子・スカーフ
        case "229": // ジュエリー
        case "262": // 雨具
        case "227": // 靴
        case "230": // 生地
        case "232": // 腕時計 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '225')"); // アパレル&アクセサリー
            break;

        case "252": // カー部品 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '251')"); // カー用品
            break;

        case "266": // 家電
        case "222": // オーディオ・映像装置
        case "221": // その他のデジタル製品 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '17')"); // デジタル製品&家電
            break;

        case "204": // 乾燥食品
        case "197": // 飲料品
        case "203": // 青果品
        case "206": // 肉類
        case "199": // 面類・米&小麦
        case "202": // ソース類
        case "201": // スパイス・調味料類
        case "200": // お菓子・スナック類
        case "205": // 野菜類 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '198')"); // 飲食料品
            break;

        case "218": // 浴槽製品
        case "220": // 家具
        case "216": // キッチン用具・食器
        case "219": // 伝統工芸品
        case "272": // 雑貨 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '217')"); // 家具・キッチン用具・食器
            break;

        case "254": // すべての農作製品 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '253')"); // 農作製品
            break;

        case "236": // アニメ製品
        case "237": // ギフト製品
        case "234": // 玩具 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '235')");: // ギフト・玩具・アニメ製品
            break;

        case "214": // 美容器具・製品
        case "208": // 化粧品
        case "211": // 香水
        case "212": // スキンケア製品
        case "213": // 石鹸・洗髪料
        case "210": // サプリメント・ビタミン 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '209')"); // 健康・美容製品
            break;

        case "250": // 工業製品
        case "248": // 建設資材
        case "247": // 床材
        case "264": // 水周り製品 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '249')");: // 工業・建設資材&製品
            break;

        case "269": // エネルギー・ソーラー
        case "245": // 照明 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '244')"); // 照明・エネルギー
            break;

        case "242": // 芸術品
        case "243": // 高級ステレオ 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '241')"); // 高級製品
            break;

        case "261": // 医療品・医薬品
        case "267": // 化学製品
        case "268": // 研究器具 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '260')"); // 医療品・化学製品・研究器具
            break;

        case "240": // オフィス用品
        case "263": // スクラッチカード
        case "169": // 文房具 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '238')"); // オフィス什器・文房具
            break;

        case "259": // スポーツ器具
        case "256": // スポーツウェア
        case "258": // 運動補助器具 
            $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '257')"); // スポーツ関連
            break;

            default
        }

I tried with and without brackets around the numbers. But the whole page breaks from this code...

4
  • invalid php code? -> "default"? Commented Feb 9, 2016 at 10:37
  • What do you mean by "page breaks" ? Any error messages? By the way you dont need the default at the last line. Commented Feb 9, 2016 at 10:37
  • wrong creation of switch cases, create single single switch cases. thanks Commented Feb 9, 2016 at 10:37
  • Typo. Missing : after an unnecessary default Commented Feb 9, 2016 at 10:39

1 Answer 1

4

You've left the default clause unterminated here:

case "258": // 運動補助器具 
        $wpdb->query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ('".$post_id."', '257')"); // スポーツ関連
        break;

        default
}

Try finishing it, in the simplest way like so:

default:
    break;

Also, make sure to log, display and read your errors, they help a lot.

Sign up to request clarification or add additional context in comments.

3 Comments

Hey i tried adding this, but the page still show blank.
That means that you have some other error in your code. You have to enable error display or check your server logs. Try putting this at the very first line in the PHP file, immediately after the opening <?php tag: ini_set('display_errors', 1); error_reporting(E_ALL);
Thank you so much! The error was some ;: in the switch statement! PHP is very sensitive!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.