justlukeyou Posted December 5, 2012 Share Posted December 5, 2012 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> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 5, 2012 Share Posted December 5, 2012 Use a conditional statement. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 5, 2012 Share Posted December 5, 2012 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'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.