SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    If Blank Update "No Details Submitted"

    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:

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

    Can anyone advise how I should do this please?

    Code:
    	 <?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>

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    A proper design would most likely go against what you want to accomplish here. If they do not submit details, then just leave it null. Now if you want to display a notice to the user to notify them of this, such as the "echo" part pf your post would imply. then you'd do something like:

    Code:
    if ($budget1 == null) {
    echo "Record inserted, however, you did not supply any details."
    }
    Also, please consider using PDO in the future: http://php.net/manual/en/book.pdo.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •