从 PHP 包含文件获取值后显示/隐藏 HTML 表单

发布于 2024-11-09 03:43:04 字数 3441 浏览 0 评论 0原文

我需要完成的是查看用户在其购物历史记录中是否确实存在现有的有效产品,然后才能对产品进行评论。我希望能够实现的是,如果他符合标准,则显示审核表格;如果他不符合标准,则根本不显示。我的 php 脚本如下:

 <?php
session_start();

//Remove the item from the cart
            $username="root";
            $password="sexy";
            $database="mysql";

            mysql_connect(localhost,$username,$password);
            @mysql_select_db($database) or die( "Unable to select database");
            $query="SELECT * FROM Orders where username='".$_SESSION['username']."'";
            $result=mysql_query($query);

            $num=mysql_numrows($result);



        $i=0;
        $canreview = "false";
        while ($i < $num) {
            $orderid = mysql_result($result,$i,"order_id");
            $query2="SELECT * FROM Orderlines where order_id='".$orderid."' AND product_id='".$_SESSION['reviewfruit']."'";
            $result2=mysql_query($query2);
            $num2 = mysql_numrows($result2);
            if($num2 > 0){
                $canreview = "true";
            }

        $i++;
        }
    echo $canreview;
//Re-organize the cart
//array_unshift ($_SESSION['SHOPPING_CART'], array_shift ($_SESSION['SHOPPING_CART']));
//Clear the URL variables
                mysql_close();

?>

我的 html 表单如下:

        <form id="form1" name="form1" action="" method="POST">
        <fieldset class="review">
            <table border=0.2>
                <thead>
                    <tr>
                        <th>Rating</th>
                        <th>Comment</th>
                    </tr>
                </thead>
                    <tr width=1024>
                        <td><select id = "Rating" name="Rating">
                        <option value="Please Choose">Please Choose</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                        <option value="10">10</option>
                        </select>
                        </td>
                        <td>
                        <textarea id="Comment" name="Comment" rows=3 width=300 ></textarea>
                        </td>
                    </tr>
                    <tr>
                    <td><div id="errorRating"></div></td>
                    <td><div id="errorComment"></div></td>
                    </tr>
                    <input type="hidden" id="Product_id" name="Product_id" value="<?php echo $primarykey;?>" />

            </table>
            <input type="button" value="Submit Review" name="submit" id="submit">
            <div id="errorDb"></div>
        </fieldset>
    </form>

我想知道如何使用 php 脚本中的 $canreview 变量来显示表单。

任何帮助表示赞赏!

What I need to accomplish is to see if a User actually has an existing valid product in his shopping history before he can review on a product. What i want to be able to achieve is to display the review form if he meets the criteria, or not show it at all if he doesnt. My php script is as follows :

 <?php
session_start();

//Remove the item from the cart
            $username="root";
            $password="sexy";
            $database="mysql";

            mysql_connect(localhost,$username,$password);
            @mysql_select_db($database) or die( "Unable to select database");
            $query="SELECT * FROM Orders where username='".$_SESSION['username']."'";
            $result=mysql_query($query);

            $num=mysql_numrows($result);



        $i=0;
        $canreview = "false";
        while ($i < $num) {
            $orderid = mysql_result($result,$i,"order_id");
            $query2="SELECT * FROM Orderlines where order_id='".$orderid."' AND product_id='".$_SESSION['reviewfruit']."'";
            $result2=mysql_query($query2);
            $num2 = mysql_numrows($result2);
            if($num2 > 0){
                $canreview = "true";
            }

        $i++;
        }
    echo $canreview;
//Re-organize the cart
//array_unshift ($_SESSION['SHOPPING_CART'], array_shift ($_SESSION['SHOPPING_CART']));
//Clear the URL variables
                mysql_close();

?>

and my html form is as follows :

        <form id="form1" name="form1" action="" method="POST">
        <fieldset class="review">
            <table border=0.2>
                <thead>
                    <tr>
                        <th>Rating</th>
                        <th>Comment</th>
                    </tr>
                </thead>
                    <tr width=1024>
                        <td><select id = "Rating" name="Rating">
                        <option value="Please Choose">Please Choose</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                        <option value="10">10</option>
                        </select>
                        </td>
                        <td>
                        <textarea id="Comment" name="Comment" rows=3 width=300 ></textarea>
                        </td>
                    </tr>
                    <tr>
                    <td><div id="errorRating"></div></td>
                    <td><div id="errorComment"></div></td>
                    </tr>
                    <input type="hidden" id="Product_id" name="Product_id" value="<?php echo $primarykey;?>" />

            </table>
            <input type="button" value="Submit Review" name="submit" id="submit">
            <div id="errorDb"></div>
        </fieldset>
    </form>

What I want to know is how I can use my $canreview variable from my php script to show the form.

Any help is appreciated!!

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

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

发布评论

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

评论(1

厌味 2024-11-16 03:43:04

你需要这样的东西:

if ($canreview) {
    include 'theform.php';
}

You need something like this:

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