使用PHP发送基于Guet数量的特定URL

使用PHP发送基于Guet数量的特定URL,php,wordpress,web,Php,Wordpress,Web,我已经编写了一个小代码,允许我基于表单提交在自动回复电子邮件中发送特定链接。换句话说,我有一个由用户填写的联系表,根据他们在现场的客人数量,他们将收到一个或另一个链接。到目前为止,我所得到的效果很好,但我想创建一个规则,以防它们在输入字段中输入零作为值。我想要的是,当他们输入0时,代码可以告诉他们0来宾不是有效数字。希望我说的很清楚,提前谢谢你的帮助 <?php // This value will be grabbed from a form. $guests = 21

我已经编写了一个小代码,允许我基于表单提交在自动回复电子邮件中发送特定链接。换句话说,我有一个由用户填写的联系表,根据他们在现场的客人数量,他们将收到一个或另一个链接。到目前为止,我所得到的效果很好,但我想创建一个规则,以防它们在输入字段中输入零作为值。我想要的是,当他们输入0时,代码可以告诉他们0来宾不是有效数字。希望我说的很清楚,提前谢谢你的帮助

<?php

    // This value will be grabbed from a form.
    $guests = 21; // Enter some numeric value here.

    // This is the Brochure's URL in 3 different options, depending on the Nº of guests.
    $brochure = array ( '0' => 'http://www.yahoo.com', '1' => 'http://www.google.co.uk', '2' => 'http://www.kazzabe.com' );

    // Start asking number of guests.
    if ( $guests <= 10 ) {
        // Between 1 and 10.
        $brochure_link = $brochure[0]; 
    } else if ( $guests >= 11 && $guests <= 20 ) {
        // Between 11 and 20.
        $brochure_link = $brochure[1]; 
    } else ( $guests >= 21 ) {
        // More than 20.
        $brochure_link = $brochure[2] 
    };

    echo 'As there will be <b>'.$guests.'</b> guests at your wedding, we proceed to send you the brochure you have requested. In order to download it, please follow this <a href="'.$brochure_link.'" target="_blank">link.</a>';

因此,您要做的第一件事是测试零来宾,抛出一个错误并退出

<?php

    // This value will be grabbed from a form.
    $guests = 21; // Enter some numeric value here.

    // This is the Brochure's URL in 3 different options, depending on the Nº of guests.
    $brochure = array ( '0' => 'http://www.yahoo.com', '1' => 'http://www.google.co.uk', '2' => 'http://www.kazzabe.com' );

    // Start asking number of guests.
    if ( $guests == 0 ) {
        echo 'Zero (0) is not a valid Nº of guests. Please try adding a number major than zero.';
        exit;
    } else if ( $guests <= 10 ) {
        // Between 1 and 10.
        $brochure_link = $brochure[0]; 
    } else if ( $guests >= 11 && $guests <= 20 ) {
        // Between 11 and 20.
        $brochure_link = $brochure[1]; 
    } else {
            if ( $guests >= 21 ) {
                // More than 20.
                $brochure_link = $brochure[2];
            }
    }

    echo 'As there will be <b>'.$guests.'</b> guests at your wedding, we proceed to send you the brochure you have requested. In order to download it, please follow this <a href="'.$brochure_link.'" target="_blank">link.</a>';

我们将
if($guests==0)
的测试添加到您的测试中。我已经将其作为第一个选项进行了测试,但我删除了它,因为它对我不起作用。我不知道我是否做错了什么。你能帮我做些样品吗?谢谢@RiggsFolly我的错误是只使用了一个=符号,而不是使用了两个==再次感谢!哈,那条消息只是为了演示,不是真正的建议用户消息没关系,我只是在编辑主文件时添加的,;)