Thread: Help using if

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    76
    Rep Power
    7

    Help using if


    I am attempting to create a form that a friend and I use on a regular basis.

    I have this set up to test currently on my host at http://mypricesavings.com/rma/index.php when the confirm button is pressed it loads process.php which basically shows what was entered into the form.

    I would like to know how to implement the If so that if there is no data or video equipment entered into the form it omits that from the confirmation page.

    here is the php code for process.php where the if should go, I am just not sure how to implement it.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <title>Pavlov Media RMA Request</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <link rel="stylesheet" type="text/css" href="css/default.css"/>
        </head>
        <body>    
            <form action="" class="register">
                <h1>Complete Tech Solution / Pavlov Media RMA Request</h1>
                <?php if(isset($_POST)==true && empty($_POST)==false): 
                    
    $chkbox $_POST['chk'];
                    
    $site $_POST['site'];
                    
    $day $_POST['day'];
                    
    $month $_POST['month'];
                    
    $problem $_POST['problem'];
                    
    $type $_POST['type'];
                    
    $sc $_POST['sc'];
                    
    $item=$_POST['item'];
                    
    $model=$_POST['model'];            
                    
    $serial=$_POST['serial'];
                    
    $problemd=$_POST['problemd'];
                    
    $itemv=$_POST['itemv'];
                    
    $modelv=$_POST['modelv'];            
                    
    $serialv=$_POST['serialv'];
                    
    $problemv=$_POST['problemv'];                    
                
    ?>
                <fieldset class="row1">
                    <legend>Property Details</legend>
                    <p>
                        <label>Site Name 
                        </label>
                        <input name="site" type="text" readonly="readonly" value="<?php echo $site ?>"/>
                        <label>Date of Request
                        </label>
                        <input type="text" readonly="readonly" class="small" value="<?php echo $month ?>"/>
                        <input type="text" readonly="readonly" class="small" value="<?php echo $day ?>"/>
                        <input type="text" readonly="readonly" class="small" value="2013"/>
                    </p>
                    <p>
                        <label>Service Call #
                        </label>
                        <input name="sc" type="text" readonly="readonly" value="<?php echo $sc ?>"/>
                    </p>
                    <p>
                        <label>Problem Description
                        </label>
                        <input name="problem" type="text" readonly="readonly" value="<?php echo $problem ?>"/>                    
                    </p>
                    
                    <div class="clear"></div>
                </fieldset>
                <fieldset class="row2">
                    <legend>Equipment Details
                    </legend>    
                    <?php if (isset($item)) { ?>             
                    <table id="dataTable" class="form" border="1">
                        <tbody>
                        <tr>
                        
                           <th></th>
                           <th>Router-Switch-AP</th>
                           <th>Model</th>
                           <th>Serial #</th>
                           <th>Problem</th>
                        </tr>
                        <?php foreach($item as $a => $b){ ?>
                            <tr>
                                <p>
                                    <td >
                                        <?php echo $a+1?>
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="item[$a]" value="<?php echo $item[$a]; ?>">
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="model[]" value="<?php echo $model[$a]; ?>">
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="serial[]" value="<?php echo $serial[$a]; ?>">
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="problemd[]" value="<?php echo $problemd[$a]; ?>">
                                    </td>
                                </p>
                            </tr>
                        <?php } } ?>
                        </tbody>
                    </table>
                    <table id="dataTable2" class="form" border="1">
                        <tbody>
                        <tr>
                           <th></th>
                           <th>RCVR-Modulator-Fiber</th>
                           <th>Model</th>
                           <th>Serial #</th>
                           <th>Problem</th>
                        </tr>
                        <?php foreach($item as $a => $b){ ?>
                            <tr>
                                <p>
                                    <td >
                                        <?php echo $a+1?>
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="itemv[$a]" value="<?php echo $itemv[$a]; ?>">
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="modelv[]" value="<?php echo $modelv[$a]; ?>">
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="serialv[]" value="<?php echo $serialv[$a]; ?>">
                                    </td>
                                    <td>
                                        <input type="text" readonly="readonly" name="problemdv[]" value="<?php echo $problemv[$a]; ?>">
                                    </td>
                                </p>
                            </tr>
                        <?php ?>
                        </tbody>
                    </table>
                    <div class="clear"></div>
                </fieldset>
                <fieldset class="row3">
                    <legend>Further Information</legend>                  
                        <p>This Form most be provided for Proper Invoicing.  Instructions must be followed.</p>
                    <div class="clear"></div>
                </fieldset>
                
            <?php else: ?>
            <fieldset class="row1">
                <legend>Sorry</legend>
                 <p>Some things went wrong please try again.</p>
            </fieldset>
            <?php endif; ?>
                <div class="clear"></div>
            </form>
        </body>
        
    </html>
    I am not good at programming, I found this code and I modified it to my needs thus far so I am not the original author.

    Thank you in advance for your help
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    Generally, one would simply check if a variable is set at all and holds any true value (not blank). A value can be set, and blank. Blankness is value. So the example below would generally do such.
    PHP Code:
    if(isset($var) && $var != '') {
      
    // Your code here if the variable holds value.

    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him

IMN logo majestic logo threadwatch logo seochat tools logo