Jump to content

[SOLVED] show if form varible not empty


emediastudios

Recommended Posts

I need an alteration to my code to show region only if the form varible from the previous file is not empty.

 

I have a list of properties in a table called employees, database name gcproperty.

Some properties dont have full records in the fields (photo1, photo2, etc..........to photo9. and are empty.

On the show all details page some images are blank as there is no record in the database or where drawn from the form varibles browse page that where also empty.

 

Does this make sense? ???  ???

 

here is the code for image 2, the rest are the same

 

table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo2']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo2']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

Link to comment
Share on other sites

do you mean that if $_POST['photo2'] is not empty, then display or not don't display. ...? if that's what you mean...just do this:

 

table width="150" border="0">
  <tr>
    <td>
     <?php
     if (isset($_POST['photo2']))
     {
       echo "<a href='images/".$_POST['photo2']."' target='_blank'><img src='images/".$_POST['photo2']."'      alt='image' width='150' border='0' /></a>";
     }
     else
     {
       echo "N/A";
     }
     ?>
    <br />
   </td>
  </tr>
</table>

 

in the above i use the isset() function to test if $_POST['photo2'] is set or not...if its set, then display the image, else display n/a. see the manual to learn more about variables : http://www.php.net/manual/en/ref.var.php

Link to comment
Share on other sites

Sure Here it is

 

</table>
  <table width="645" align="center">
    <tr>
      <td colspan="2" align="left" valign="top" bordercolor="#000000" bgcolor="#F1F1F1"><div align="left"><span class="style1"><u> <?php echo $_POST['name']; ?></u></span> </div>
      <div align="right"></div></td>
    </tr>
    <tr>
      <td width="173" align="left" valign="top" bordercolor="#000000" bgcolor="#FFFFFF"><table width="156" border="0">
          <tr>
            <td width="150" height="403" valign="top">
           <table width="150" border="0">
  <tr>
    <td> <br /></td><?php
     if (isset($_POST['photo2']))
     {
       echo "<a href='images/".$_POST['photo2']."' target='_blank'><img src='images/".$_POST['photo2']."'      alt='image' width='150' border='0' /></a>";
     }
     else
     {
       echo  "N/A";
     }
     ?>
  </tr>
</table>

              <br />
          <table width="150" border="0">
  <tr>
   <td><a href="images/<?php echo $_POST['photo3']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo3']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
           <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo4']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo4']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>
<br />

            <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo5']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo5']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
            <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo6']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo6']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
            <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo7']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo7']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

 

And this is the file code that sends the data

 

<form action="full_details.php" method="post" enctype="multipart/form-data" name="properties" target="_self" id="properties">
      <table width="600" align="center" bgcolor="#F1F1F1">
      <tr>
        <td width="437" align="left" valign="top" bordercolor="#000000" bgcolor="#FFFFFF"><span class="style1"><u><?php echo $row_Recordset1['name']; ?></u></span><span class="style3">
        <label>
        <input name="name" type="hidden" id="name" value="<?php echo $row_Recordset1['name']; ?>" />
        </label>
        <label></label>
        </span> <span class="style3"><br />
          <span class="style5"><?php echo $row_Recordset1['price']; ?>
          <label></label>
          <label>
          <input name="price" type="hidden" id="price" value="<?php echo $row_Recordset1['price']; ?>" />
          </label>
          <br />
          <?php echo $row_Recordset1['suburb']; ?>
          <label></label>
          <label>
          <input name="suburb" type="hidden" id="suburb" value="<?php echo $row_Recordset1['suburb']; ?>" />
          </label>
          <br />
          </span></span><span class="style3"><?php echo $row_Recordset1['content']; ?>
          <label>
          <input name="content" type="hidden" id="content" value="<?php echo $row_Recordset1['content']; ?>" />
          <input name="content2" type="hidden" id="content" value="<?php echo $row_Recordset1['content2']; ?>" /><br />
<input name="photo" type="hidden" id="photo" value="<?php echo $row_Recordset1['photo']; ?>" />
          <br />
<input name="photo2" type="hidden" id="photo2" value="<?php echo $row_Recordset1['photo2']; ?>" />
          <br />
</label>
          

          <label>
          <input name="photo3" type="hidden" id="photo3" value="<?php echo $row_Recordset1['photo3']; ?>" />
          </label>
          <label>
          <input name="photo4" type="hidden" id="photo4" value="<?php echo $row_Recordset1['photo4']; ?>" />
          </label>
          <label>
          <input name="photo5" type="hidden" id="photo5" value="<?php echo $row_Recordset1['photo5']; ?>" />
          </label>
          <label>
          <input name="photo6" type="hidden" id="photo6" value="<?php echo $row_Recordset1['photo6']; ?>" />
          </label>
          </span>
          <label>
          <input name="photo7" type="hidden" id="photo7" value="<?php echo $row_Recordset1['photo7']; ?>" />
          <input name="photo8" type="hidden" id="photo8" value="<?php echo $row_Recordset1['photo8']; ?>" />
          <input name="photo9" type="hidden" id="photo9" value="<?php echo $row_Recordset1['photo9']; ?>" />
          </label></td>
        <td width="151"><div align="center"><a href="images/<?php echo $row_Recordset1['photo']; ?>" target="_blank"><img src="images/<?php echo $row_Recordset1['photo']; ?>" alt="image" width="150" border="0" /></a></div></td>
      </tr>
      
      
      <tr>
        <td colspan="2"></td>
      </tr>
      
      <tr>
        <td height="23" colspan="2" bgcolor="#666666"><a href="full_details.php" target="_self">
          <label>
          <input type="submit" name="submit" id="submit" value="more info" />
          </label>
        </a></td>
      </tr>
    </table>
    </form>

Link to comment
Share on other sites

I used this code and it works like i wish, seems strange as to me it feel like its reversed.

 

<?php
     if (!empty($_POST['photo2']))
     {
       echo "<a href='images/".$_POST['photo2']."' target='_blank'><img src='images/".$_POST['photo2']."'      alt='image' width='150' border='0' /></a>";
     }
     else
     {
       echo  "";
     }
     ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.