Simple html form using php and mysql. How do l maintain NULL values for empty fields in the database -


i have built simple html form has input boxs , text areas, inserted mysql database of php script. not fields have filling in , l want able search database null fields. problem when form submits, entries have no information having inserted empty space means l can't search db null fields returns everything.

this php script sends mysql insert query db

<?php /*av tech name*/ $technam = $_post['technam']; /* building */ $building = $_post['building']; /* room */  $roomnum = $_post['roomnum']; /* day */ $day = $_post['day']; /*month*/ $month = $_post['month']; /*projector power */ $projpower = $_post['projpower']; /* screen decends , retracts */ $screenupdown = $_post['screenupdown']; /* power buton control */ $controlpower = $_post['controlpower']; /* lamp working */ $projlamp = $_post['projlamp']; /* rips , tears screen */ $rips = $_post['rips']; /* control functions */ $controlfunctions = $_post['controlfunctions']; /* projector image */ $projimage = $_post['projimage']; /* screen notes */ $screennotes = $_post['screennotes']; /* control notes */ $controlnotes = $_post['controlnotes']; /* monitor power */ $monitorpower = $_post['monitorpower']; /* network connection */ $networkconnect = $_post['networkconnect']; /* pc power */ $pcpower = $_post['pcpower']; /* pc image */ $pcimage = $_post['pcimage']; /* pc audio */ $pcaudio = $_post['pcaudio']; /* pc dvd playback */ $pcdvd = $_post['pcdvd']; /* bluray player power */ $bluraypower = $_post['bluraypower']; /* laptop vga connection */ $laptopvga = $_post['laptopvga']; /* visualiser power */ $vispower = $_post['vispower']; /* bluray play */ $blurayplay = $_post['blurayplay']; /* laptop audio */ $laptopaudio = $_post['laptopaudio']; /* visualiaser lamp */ $vislamp = $_post['vislamp']; /* bluray audio */ $blurayaudio = $_post['blurayaudio']; /* laptop hdmi */ $laptophdmi = $_post['laptophdmi']; /* visualiser image */ $visimage = $_post['visimage']; /* laptop network connection */ $laptopnetwork = $_post['laptopnetwork']; /* visualiser automatic , manual zoom */ $viszoom = $_post['viszoom']; /* lectern mic working */ $miclec = $_post['miclec']; /* video conference power */ $vcpower = $_post['vcpower']; /* condition of lectern condition */ $lecterncondition = $_post['lecterncondition']; /* radio mics working */ $audioradiomics = $_post['audioradiomics']; /* vc unit dials , connects */ $vcconnect = $_post['vcconnect']; /* general condition of cables */ $cablecondition = $_post['cablecondition']; /* visualiser audio */ $vcaudio = $_post['vcaudio']; /* condition of wall connections */ $wall = $_post['wall']; /* visualiser laptop connection */ $vclaptop = $_post['vclaptop']; /* white board condition */ $whiteb = $_post['whiteb']; /* video conference notes */ $vcnotes = $_post['vcnotes'];  $sql = "insert avchecklist (technam, building, roomnum, day, month,  projpower, screenupdown, controlpower, projlamp, rips, controlfunctions,  projimage, screennotes, controlnotes, monitorpower, networkconnect,  pcpower, pcimage, pcaudio, pcdvd, bluraypower, laptopvga, vispower,  blurayplay, laptopaudio, vislamp, blurayaudio, laptophdmi, visimage,  laptopnetwork, viszoom, miclec, vcpower, lecterncondition,  audioradiomics, vcconnect, cablecondition, vcaudio, wall, vclaptop,  whiteb, vcnotes) values ('$technam', '$building', '$roomnum', '$day',  '$month', '$projpower', '$screenupdown', '$controlpower', '$projlamp',  '$rips', '$controlfunctions', '$projimage', '$screennotes',  '$controlnotes', '$monitorpower', '$networkconnect', '$pcpower',  '$pcimage', '$pcaudio', '$pcdvd', '$bluraypower', '$laptopvga',  '$vispower', '$blurayplay', '$laptopaudio', '$vislamp', '$blurayaudio',  '$laptophdmi', '$visimage', '$laptopnetwork', '$viszoom', '$miclec',  '$vcpower', '$lecterncondition', '$audioradiomics', '$vcconnect',  '$cablecondition', '$vcaudio', '$wall', '$vclaptop', '$whiteb',  '$vcnotes')";   if (!mysql_query($sql)) {  die('error: ' . mysql_error());  } echo 'thanks '. $technam .' completed maintenance check room '.  $roomnum .'  has been added database.'; echo "<br /><br /><br />"; echo 'this page redirect in 5 seconds'; mysql_close(); ?> 

table structure

database a9404870_heav table structure table avchecklist field   type    null    default submitdate  timestamp   yes current_timestamp technam varchar(255)    yes null building    varchar(255)    yes null roomnum varchar(255)    yes null day varchar(255)    yes null month   varchar(255)    yes null projpower   varchar(255)    yes null screenupdown    varchar(255)    yes null controlpower    varchar(255)    yes null projlamp    varchar(255)    yes null rips    varchar(255)    yes null controlfunctions    varchar(255)    yes null projimage   varchar(255)    yes null screennotes varchar(255)    yes null controlnotes    varchar(255)    yes null monitorpower    varchar(255)    yes null networkconnect  varchar(255)    yes null pcpower varchar(255)    yes null pcimage varchar(255)    yes null pcaudio varchar(255)    yes null pcdvd   varchar(255)    yes null bluraypower varchar(255)    yes null laptopvga   varchar(255)    yes null vispower    varchar(255)    yes null blurayplay  varchar(255)    yes null laptopaudio varchar(255)    yes null vislamp varchar(255)    yes null blurayaudio varchar(255)    yes null laptophdmi  varchar(255)    yes null visimage    varchar(255)    yes null laptopnetwork   varchar(255)    yes null viszoom varchar(255)    yes null miclec  varchar(255)    yes null vcpower varchar(255)    yes null lecterncondition    varchar(255)    yes null audioradiomics  varchar(255)    yes null vcconnect   varchar(255)    yes null cablecondition  varchar(255)    yes null vcaudio varchar(255)    yes null wall    varchar(255)    yes null vclaptop    varchar(255)    yes null whiteb  varchar(255)    yes null vcnotes varchar(255)    yes null 

in order make sure set null have this:

isset($_post['screennotes'])? $screennotes = $_post['screennotes'] : $screennotes = null; 

you have every field wish insert null's if field left blank.

what have done here use ternary condition - shortened if condition:

<if true> ? <do this> : <else that>; 

for more on ternary operatores see the docs.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -