Jump to content

If Blank Insert "no Details Submitted"?


justlukeyou

Recommended Posts

Hi,

 

I have simple insert code and form. However I want people to be able leave some fields blank if they want to. Yet inserted into the database is "No Details Submitted".

 

For example if someone does not want to submit a budget they can leave the cell blank but I want to echo something to say that "No Details Submitted"

 

I need something like this:

 

    if(!isset($_POST['budget']) || empty($_POST[budget'])) {
   INSERT INTO eventjobs  = "No Details Submitted.";

   }

 

 

Can anyone advise how I should do this please? I also need to this with an image. For example. If blank insert "defaultimage.png" so i can display a default image.

 

     <?php
    if(isset($_POST['createevent'])){
   $organiserid = $row['id'];
   $eventlocation = $row['town'];
   $eventcountry = $row['country'];
   $eventname = mysql_real_escape_string(trim($_POST['eventname']));
   $eventdetails = mysql_real_escape_string(trim($_POST['eventdetails']));
   $supplier1 = mysql_real_escape_string(trim($_POST['supplier1']));
   $budget1 = mysql_real_escape_string(trim($_POST['budget1']));


{
    $query = mysql_query("INSERT INTO eventjobs (dateregistered, eventname, eventdetails, organiserid, eventlocation, eventcountry, supplier1, budget1) VALUES (NOW(), '" .$eventname."','" .$eventdetails."',  '" .$organiserid."', '" .$eventlocation."',  '" .$eventcountry."',   '" .$supplier1."', '" .$budget1."' ) ");
    }
}

?>





             <div class="registerinputcelltop">
                   <div class="datainput">
                   <li class="li_1" >
             <div class="registerinputleft">    
	   Event Name (Optional):
           </div>
             <div class="registerinputright">
	 <input class="field" type="text" name="eventname" type="text" width="600" value="" />  
	   </div>
             </li>
              	 </div>
              	   </div>

Link to comment
Share on other sites

I would suggest a different approach. Instead of submitting a default value into the database, go ahead and insert a null or empty value. THEN, when selecting records and displaying to a page implement logic to show the message if the value is empty.

 

So, the logic you have on the script to INSERT the records would stay the same, respective to the solution you want. But, you have some gaps in the logic for checking that the values are actually valid and exist.

 

Then on the script(s) to display the values you can do one of two things:

 

1. Modify the SELECT query to set the default message in the results where the value is null/empty

SELECT field1, field2, IF(image<>'', image, 'default_image.jpg') as image_src
FROM table

- or -

 

2. Implement logic in the PHP code to use the default message in the results where the value is empty

while($row = mysql_fetch_assoc($result))
{
   $image = ($row['image'] != '') ? $row['image'] : 'default_image.jpg';
}

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.