Hi everyone, I have been trying to write a php script to display a div and its contents depening on a result from mysql.

Inside the div is a basic input form etc, nothing special, some error & validation checking.

What I would like to do is, to only display the div and contents if a result from my database was true.

        $res = mysql_query("SELECT var, var1 FROM tbl_name WHERE var='$var' && var1='0'") or die(mysql_error()); 

            $checkvar = mysql_num_rows($res);

            if($checkvar > 0){ 

                $row = mysql_fetch_array($res);
                $var = $row['var'];

                if ($var1 == 0)
                { //if result is false
                // do not display the div and contents
                //if the result = 1 display the div and contents here

Here is the complete form. Inside the form there are php tags so I am not sure how to get around this

    <!-- Begin #optIn -->
    <div id="optIn">
        <div class="optBox">
        <h3><?php if($headline){echo $headline; }?></h3>
        <p><?php if($dealdetails){echo $dealdetails; }?></p>

        <form style="width:100%;" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
        <label class="previewLabel" for="awf_field"></label>

       <select name="country" tabindex="1" class="select" value='<?php echo $country; ?>' id="country" onChange="get_country_code();">
                            <?php if($country!=''){?>
                            <option value="<?php echo $country;?>"><?php echo $country;?></option>
                            <?php }else{ ?>
                            <option value="">Please Select Country</option>
                            <?php }?>
                                 while($country_arr = mysql_fetch_array($result_country)){
                                    $tag_selected = ( (isset($_POST['country']) and $_POST['country'] == $country_arr['Country'] )? 'selected="selected"' : '' );
                                     <option value="<?php echo $country_arr['Country']?>" <?php echo $tag_selected; ?>><?php echo $country_arr['Country']?></option>

        <input type="text" class="text" id="smsmobnum" maxlength="11" size="11" name="smsmobnum" title="Enter your full mobile number" value="<? echo $smsmobnum; ?>" tabindex="2">

        <input type="submit" name="submit" class="submit btn" title="Click &amp; Be Rewarded" value="Get This Deal Now" tabindex="502">
        <input type="hidden" name="dialingCode" id="dialingCode" maxlength="5" size="5" readonly value="<? echo $dialingCode; ?>">
        <div class="p">
        <?php printErrors(); ?>
        <?php echo $msg_success; ?></div>
        <p>Select your country and enter your full mobile number to subscribe. <strong>All Sms Coupons &amp; Deals Are 100% FREE To Receive.</strong></p>      
        <div align="left">
        <form action="unsms.php" method="LINK"><input type="submit" class="orange-btn" title="Remove your mobile number" value="Unsubscribe"></form>
        <div class="optBoxb"></div>
    <!-- end #optIn -->

Any help would be appreciated,

Line 10 checks $var1, but it is not given any value. Perhaps you wanted to check $var ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.