当用户输入错误代码时不会弹出消息

发布于 2024-11-02 13:29:12 字数 4374 浏览 0 评论 0原文

我制作了一个表单,允许用户在输入正确的优惠券代码时提交和更新他们的广告,但我无法收到“无效的优惠券代码”消息。当他们输入错误的优惠券代码时回显。

这是我的代码:

<? require("connect.php"); ?>

<form action="advertisement.php" method="POST" enctype="multipart/form-data">
<table width="50%" border="0" cellspacing="0" cellpadding="8">
    <tr> 
       <td><div align="right"> Apartment:</div></td> 
       <td><select name="apartment" id="apartment"> 
        <option>Place Ad In Which Apartment...</option> 
        <option value="0">Archstone La Jolla</option>
        <option value="1">Archstone La Jolla Colony</option>
        <option value="2">Archstone UTC</option>
        <option value="3">Canyon Park</option>
        <option value="4">Costa Verde Village</option>
        <option value="5">Costa Verde Towers</option>
        <option value="6">La Jolla Crossroads</option>
        <option value="7">La Jolla Del Sol</option>
        <option value="8">La Jolla International Garden</option>
        <option value="9">La Jolla Palms</option>
        <option value="10">La Mirada</option>
        <option value="11">La Regencia</option>
        <option value="12">La Scala</option>
        <option value="13">Las Flores</option>
        <option value="14">The Villas</option>
        <option value="15">Nobel Court</option>
        <option value="16">Pacific Gardens</option>
        <option value="17">Regents Court</option>
        <option value="18">Regents La Jolla</option>
        <option value="19">Trieste</option>
        <option value="20">Valentia</option>
        <option value="21">Whispering Pines</option></select></td>
   </tr>
    <tr>
       <td><div align="right">Description:</div></td>
       <td><textarea name="description" id="description" cols="55" rows="7" wrap="VIRTUAL"></textarea></td>
    </tr>
    <tr>
       <td><div align="right">Coupon Code:</div></td>
       <td><input type="text" name="code" size="60"></td>
    </tr>
    <tr> 
       <td></td>
       <td><div align="left">
        <input type="reset" value="Clear">     
        <input type="submit" name="submit" value="Submit"></div></td>
    </tr>
  </table>
</form>

<?php

$description = $_POST['description'];
$apartment = $_POST['apartment'];
$code = $_POST['code'];

//retrieve data from password table
$query = mysql_query ("SELECT * FROM coupon WHERE code = '$code' ");

//get number of rows in table
$numrows = mysql_num_rows ($query);

if ($numrows !=0)
{
    // gather all codes
    while ($row = mysql_fetch_assoc ($query))
    {
        //retrieve code from database to match with the code that was put into field
        $dbcode = $row['code'];
    }

    //check to see if they match
    if ($code == $dbcode )
        {
            //check to see if coupon code is in both consumer and coupon tables
            $query2 = mysql_query ("SELECT * FROM consumer WHERE code = '$code' ");

            $numrows2 = mysql_num_rows ($query2);


        while ($row2 = mysql_fetch_assoc ($query2))
        {
            $consumercode = $row2['code'];
        }
            if( $dbcode == $consumercode)
            {

                $update = mysql_query ("UPDATE consumer SET description = '$description' WHERE code ='$code'  ");           




                echo "Advertisement successfully updated.";


            }
            //if coupon not in both tables then they haven't posted advertisement yet
            else
             {


$time = time();

$day =  30;

$exp = $time + ($day * 86400);


        mysql_query ("INSERT INTO consumer VALUES ('','$description', '$exp', '$apartment', '$code')");     

        mysql_query ("UPDATE coupon SET exp = '$exp' WHERE code ='$code'  ");       


                echo "Your advertisement has been successfully submitted.";
             }

}
else
    echo "Invalid coupon code.";
}
else 
    echo "";



 ?>

I made a form to allow an user to submit and update their advertisement when they enter the right coupon code but I can't get the message "Invalid coupon code." to echo out when they enter the wrong coupon code.

heres my code:

<? require("connect.php"); ?>

<form action="advertisement.php" method="POST" enctype="multipart/form-data">
<table width="50%" border="0" cellspacing="0" cellpadding="8">
    <tr> 
       <td><div align="right"> Apartment:</div></td> 
       <td><select name="apartment" id="apartment"> 
        <option>Place Ad In Which Apartment...</option> 
        <option value="0">Archstone La Jolla</option>
        <option value="1">Archstone La Jolla Colony</option>
        <option value="2">Archstone UTC</option>
        <option value="3">Canyon Park</option>
        <option value="4">Costa Verde Village</option>
        <option value="5">Costa Verde Towers</option>
        <option value="6">La Jolla Crossroads</option>
        <option value="7">La Jolla Del Sol</option>
        <option value="8">La Jolla International Garden</option>
        <option value="9">La Jolla Palms</option>
        <option value="10">La Mirada</option>
        <option value="11">La Regencia</option>
        <option value="12">La Scala</option>
        <option value="13">Las Flores</option>
        <option value="14">The Villas</option>
        <option value="15">Nobel Court</option>
        <option value="16">Pacific Gardens</option>
        <option value="17">Regents Court</option>
        <option value="18">Regents La Jolla</option>
        <option value="19">Trieste</option>
        <option value="20">Valentia</option>
        <option value="21">Whispering Pines</option></select></td>
   </tr>
    <tr>
       <td><div align="right">Description:</div></td>
       <td><textarea name="description" id="description" cols="55" rows="7" wrap="VIRTUAL"></textarea></td>
    </tr>
    <tr>
       <td><div align="right">Coupon Code:</div></td>
       <td><input type="text" name="code" size="60"></td>
    </tr>
    <tr> 
       <td></td>
       <td><div align="left">
        <input type="reset" value="Clear">     
        <input type="submit" name="submit" value="Submit"></div></td>
    </tr>
  </table>
</form>

<?php

$description = $_POST['description'];
$apartment = $_POST['apartment'];
$code = $_POST['code'];

//retrieve data from password table
$query = mysql_query ("SELECT * FROM coupon WHERE code = '$code' ");

//get number of rows in table
$numrows = mysql_num_rows ($query);

if ($numrows !=0)
{
    // gather all codes
    while ($row = mysql_fetch_assoc ($query))
    {
        //retrieve code from database to match with the code that was put into field
        $dbcode = $row['code'];
    }

    //check to see if they match
    if ($code == $dbcode )
        {
            //check to see if coupon code is in both consumer and coupon tables
            $query2 = mysql_query ("SELECT * FROM consumer WHERE code = '$code' ");

            $numrows2 = mysql_num_rows ($query2);


        while ($row2 = mysql_fetch_assoc ($query2))
        {
            $consumercode = $row2['code'];
        }
            if( $dbcode == $consumercode)
            {

                $update = mysql_query ("UPDATE consumer SET description = '$description' WHERE code ='$code'  ");           




                echo "Advertisement successfully updated.";


            }
            //if coupon not in both tables then they haven't posted advertisement yet
            else
             {


$time = time();

$day =  30;

$exp = $time + ($day * 86400);


        mysql_query ("INSERT INTO consumer VALUES ('','$description', '$exp', '$apartment', '$code')");     

        mysql_query ("UPDATE coupon SET exp = '$exp' WHERE code ='$code'  ");       


                echo "Your advertisement has been successfully submitted.";
             }

}
else
    echo "Invalid coupon code.";
}
else 
    echo "";



 ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-11-09 13:29:12
while ($row = mysql_fetch_assoc ($query))
{
    //retrieve code from database to match with the code that was put into field
    $dbcode = $row['code'];
}

该代码块并未收集所有代码。它只是用每个代码覆盖 $dbcode,并且在块的末尾只有最后一行。

我假设其余代码应该位于该块内。

}
else
    echo "Invalid coupon code.";
}
else 
    echo "";

最后的第二个 echo 语句还应该有一条消息,我认为这将是无效的代码消息,因为它基于 if ($numrows !=0)

while ($row = mysql_fetch_assoc ($query))
{
    //retrieve code from database to match with the code that was put into field
    $dbcode = $row['code'];
}

This block of code isn't gathering all codes. It's just overwriting $dbcode with every code, and at the end of the block there is only the last row.

I am assuming that the rest of the code should be inside of this block.

}
else
    echo "Invalid coupon code.";
}
else 
    echo "";

This second echo statement at the end should also have a message, which I think would be the invalid code message, since it's based on if ($numrows !=0)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文