开发者

Display/Hide a HTML form after getting a value from a PHP include file [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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 开发者_JAVA百科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!!


You need something like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜