-1

Hi i have a registration form in my website.if the particular field in the db is null then the form should not be displayed to the user.Here if the payment_category_upload field is empty then the form should not displayed to the user otherwise the form should be displayed.

<?php include 'includes/db.php';
$sql = "SELECT * FROM users WHERE username = '$_SESSION[user]' AND user_password = '$_SESSION[password]'  AND payment_category_upload!='' ";
$oppointArr =array();
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0) 
{
if(isset($_POST['submit_user'])|| isset($_POST['save_users']))
{
    $formsubmitstatus = isset($_POST['submit_user'])?1:0;   
    if($_FILES["affidavits_upload"]["tmp_name"]!="")
    {
        $pname = rand(1000,10000)."-".str_replace("-"," ",$_FILES["affidavits_upload"]["name"]);
        $affidavits_upload = $_FILES["affidavits_upload"]["tmp_name"];
        $uploads_dir = '../admin/images/uploads';
        move_uploaded_file($affidavits_upload, $uploads_dir.'/'.$pname);
    }
    else
    {
        $pname = $_POST['hid_affidavits_upload'];
    }       
    $id= $_POST['users_id'];        
    $ins_sql = "UPDATE users set affidavits_upload='$pname',status='3',affidavitsupload_submit_status='$formsubmitstatus'  WHERE users_id = $id";
    $run_sql = mysqli_query($conn,$ins_sql);
    $msg = 'Your Application successfully submitted. ';   
    $msgclass = 'bg-success';           
}

else 
{
    $msg = 'Record Not Updated';      
    $msgclass = 'bg-danger';
}
}
else
{
  echo "Please make the payment to enable Affidavits";
}
?>

FORM :

<form class="form-horizontal" action="affidavits.php" method="post" role="form" enctype="multipart/form-data" id="employeeeditform">
                            <?php if(isset($msg)) {?>
                                <div class="<?php echo $msgclass; ?>"  id="mydiv" style="padding:5px;"><?php echo $msg; ?></div>
                            <?php } ?>
                            <input  type='hidden' value='<?=$id;?>' name='users_id'>                    
                            
                            <div class="form-group"> 
                                <label for="affidavits_upload" class="col-sm-4 control-label">Affidavits Upload</label> 
                                <div class="col-sm-8"> 
                                    <input type="hidden" value="<?php echo $oppointArr['affidavits_upload'];?>" name="hid_payment_category_upload"> 
                                    <input type="file" name="affidavits_upload" id="affidavits_upload">                     
                                        <?php if(!empty($oppointArr['affidavits_upload'])){?>
                                            <div>
                                                <a href="../admin/images/uploads/<?php echo $oppointArr['affidavits_upload'];?>"><?php echo $oppointArr['affidavits_upload'];?></a>
                                            </div>
                                        <?php }?>
                                        <span class="text" style="color:red;">Please upload PDF Format Only</span>
                                </div> 
                            </div>                                          
                            <div class="col-sm-offset-2"> 
                                <?php if($oppointArr['affidavitsupload_submit_status'] == 0){ ?>
                                <button type="submit" class="btn btn-default" name="save_users" id="save_users">Save</button>   
                                <button type="submit" class="btn btn-default" name="submit_user" id="subject">Submit Application</button>       
                                <?php } ?>                                              
                            </div>                          
                        </form>
user6728960
  • 275
  • 1
  • 4
  • 13
  • You can use a flag and based on it add a class with "display: none" to form – Shubham Srivastava Dec 14 '20 at 09:46
  • @ShubhamSrivastava not getting exactly what you are saying – user6728960 Dec 14 '20 at 09:52
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Dec 14 '20 at 12:28

1 Answers1

-1
//Add this Css class
.hiddenBlock {
    display:none
}



<div class="<?php echo isset(test_field)?"":"hiddenBlock"; ?>">
    <form>...<form>
</div>

You can do it like this for your field.

Shubham Srivastava
  • 1,807
  • 1
  • 10
  • 17