PHP - If Database Field Is Empty, How To Show On Form "empty"
What I am looking for is that if any field in a database is empty, the form comes back and puts in the word "empty" into the web page, but not the database.
I got this right now, it shows the first part fine, but the second part it doesn't show the "Empty" comment... I don't understand why... as far as I can tell the code is fine... Code: [Select] <?php //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box3">'; if (!empty($row['Nonconformity']) || !empty($row['Disposition']) || !empty($row['Comments']) || !empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />' . $row['Nonconformity'] . '</div>'; echo '<div id="dis"><span class="b">Disposition: </span><br />' . $row['Disposition'] . '</div>'; echo '<div id="comm"><span class="b">Comments: </span><br />' . $row['Comments'] . '</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />' . $row['CommentsAdditional_Details'] . '</div>';} else if (empty($row['Nonconformity']) || empty($row['Disposition']) || empty($row['Comments']) || empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />Empty</div>'; echo '<div id="dis"><span class="b">Disposition: <br /></span>Empty</div>'; echo '<div id="comm"><span class="b">Comments: <br /></span>Empty</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />Empty</div>';} echo '</div>'; ?> Similar TutorialsHi, I need to call to this text to add a all with value "blank/empty" or "0" to the dropdownlist code below.. it should be inserted int the first position in the dropdownlist and have a value blank and call to this text from the language files: $searchAll = gettext('_LANGUAGE_SEARCH_ALL',_LANGUAGE_SEARCH_ALL,false,false); example is: ratestitle=>0 gettext('_LANGUAGE_SEARCH_ALL',_LANGUAGE_SEARCH_ALL,false,false); the words it calls is "ALL" when the user selects or leaves the "ALL" in the list the value remains empty this allows the search to search everything.. basically im stuck how to get it in the dropdown list as the first default position: can anyone help? here is my code://this is a search function which calls to the field rate_title the text from the select box is matched to the database table and the search pages shows the search option is the search is successful.. I have 5 of these types of searches but cant give a broader search option to my users as the values must be selected to search--- i need the option "ALL" to have a "EMPTY" value or no value.... if (in_array("ratestitle",$searchOptions)&& $showSearchOptions ) { if (empty($sch->filter['ratestitle']) ) $selectOption=$output['LANGUAGE_SEARCH_RATESTITLE']; else $selectOption=$sch->filter['ratestitle']; $showButton=true; $query = "SELECT DISTINCT rate_title FROM #__rates_table ORDER BY rate_title ASC"; $dropDownList ="<select class=\"inputbox\" name=\"ratestitle\">"; $ratesitles =doSelectSql($query); foreach ($ratesitles as $ratetitle) { $selected=""; $rate_title=$ratetitle->rate_title; if ($ratetitle==".$sch->filter['ratestitle'].") $selected="selected"; $dropDownList .= "<option ".$selected." value=\"".$rate_title."\">".$rate_title."</option>"; } $dropDownList.="</select>"; $output['RATESTITLE']=$dropDownList; } Hello Everyone, I am having issues where people are submitting null characters on my website (I.e. %00). Currently, I check if their is a value by using the empty function, and I also am checking if the value after running the trim command is =="". How can I check for these special characters to make sure that whatever they are submitting actually contains some sort of legitimate value? Thanks! Hi guys , can someone help me with this code its giving me "query was empty Error" its connecting but...? and please find attached the entire php page for clarity. Thanks . <?php //connect database require_once "connect_to_mysqli.php"; //query the datbase $sqlcommand = "SELECT post_id, title, body From posts ORDER by post_id desc"; $query = mysql_query($sqlCommand) or die (mysql_error()); while($row = mysql_fetch_array($query)) { $title = $row["title"]; echo "<h3>$title</h3>"; } // Free the result set if it is large mysql_free_result($query); // close mysql connection mysql_close(); ?> Can someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> hi all i have a problem here, Iv got a form that uploads images to a folder and updates the db with the name of that image, that work ok but if one of the upload field are left blank then the script updates the db with empty values how can i get it to only update the db with only submitted form field data???? here is the form Code: [Select] <?php if (isset($_GET['id'])) { $id = $_GET['id']; } ?> <form action="ud_image.php?id=<? echo "$id"?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table class="udp"> <tr> <th>Thumbnail:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 1:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 2:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 3:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 4:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </form> and here is the processing page <?php include("protect/password_protect.php"); error_reporting(E_ALL); include ("../includes/db_config.php"); $con = mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database) or die( "Unable to select database"); $path1= "../thumbnails/".$_FILES['ufile']['name'][0]; $path2= "../images/".$_FILES['ufile']['name'][1]; $path3= "../images/".$_FILES['ufile']['name'][2]; $path4= "../images/".$_FILES['ufile']['name'][3]; $path5= "../images/".$_FILES['ufile']['name'][4]; //copy file to where you want to store file copy($_FILES['ufile']['tmp_name'][0], $path1); copy($_FILES['ufile']['tmp_name'][1], $path2); copy($_FILES['ufile']['tmp_name'][2], $path3); copy($_FILES['ufile']['tmp_name'][3], $path4); copy($_FILES['ufile']['tmp_name'][4], $path5); ?> <html> <head> <title>Update Project Images</title> <link rel="stylesheet" type="text/css" href="../../project/backend/style.css" /> </head> <body> <table class="udip"> <tr> <th><? echo "<img src=\"$path1\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path2\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path3\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path4\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path5\" width=\"150\" height=\"150\">";?></th> </tr> <tr> <td><? echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][3]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][4]."<BR/>";?></td> </tr> <tr> <td><?echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][3]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][4]."<BR/>";?></td> </tr> <tr> <td><? echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][3]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][4]."<BR/>";?></td> </tr> </table> </body> </html> <? $filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; $filesize4=$_FILES['ufile']['size'][3]; $filesize5=$_FILES['ufile']['size'][4]; if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 != 0) { echo "We have recieved your files<p>"; } else { echo "Error in you images check and try again Database has been updated to blank images so no images will be shown on details page."; } $query = "UPDATE $db_table SET thumbnail = '".$_FILES['ufile']['name'][0]."', image1 = '".$_FILES['ufile']['name'][1]."', image2 = '".$_FILES['ufile']['name'][2]."', image3 = '".$_FILES['ufile']['name'][3]."', image4 = '".$_FILES['ufile']['name'][4]."' WHERE id = '".$_GET['id']."'"; if (!mysql_query($query,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> I am trying to add another "required field" to my PHP form, but I'm not sure what I'm doing wrong. The form and "required fields" work fine, but I am now trying to make the "Select skill level which is an "input type="radio" as a required field, but it is not working. As you can see below, I just tried adding the new "required" field the same way as the other 4 were set up, but it is not working (I think I have to do something different because the new "required field" is a "radio" type and the rest are "text"). The relevant parts of the code are below. Any assistance would be appreciated Code: [Select] <script type="text/JavaScript"> function verify() { var Skill = document.indiv_reg.skill.value; var Fname = document.indiv_reg.name.value; var Hphn = document.indiv_reg.home_num.value; var Email = document.indiv_reg.email.value; var Tname = document.indiv_reg.tname.value; if ((Fname =="") || (Skill =="") || (Hphn =="") || (Email =="") || (Tname =="")) { alert('Please Fill Out ALL Required Fields'); } else { document.indiv_reg.submit(); } } </script> <?php $url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Y76L7TX6FVRW"; $sport = $_GET['sport']; $league = $_GET['league']; $visitor = $_GET['name']; $skill = $_GET['skill']; $tname = $_GET['tname']; $tcap = $_GET['tcap']; $homephn = $_GET['home_num']; $cellphn = $_GET['cell_num']; <?php * Denotes a Required Field<br /> <br /> <form name="indiv_reg" method="GET" action="tourney_mailRedirect.php"> Sport:<br /> <input type="text" name="sport" value="'.$sport.'" readonly="readonly" /><br /> <br /> Tournament:<br /> <input type="text" size="90" name="league" value="'.$league.'" readonly="readonly" /><br /> <br /> * Please select preferred skill level:<br /> <input type="radio" name="skill" value="recreational" /> Recreational<br /> <input type="radio" name="skill" value="competitive" /> Competitive<br /> <br /> * Name:<br /> <input type="text" name="name" /><br /> <br /> * Team Name:<br /> <input type="text" name="tname" /><br /> <br /> Team Captain:<br /> <input type="text" name="tcap" /><br /> <br /> * Home Phone:<br /> <input type="text" name="home_num" /><br /> <br /> Cell Phone:<br /> <input type="text" name="cell_num" /><br /> <br /> * Email:<br /> <input type="text" name="email" /><br /> <br /> ?> I have a form where people will be putting in specific info such as their names and other info. When the form is posted I need to add a "." between the fields on the output depending on if it is filled out or not if field is blank do not need a "." Example if they put in their name Bob Marley on the form I need it to appear on the output as Bob.Marley. Here is the code using currently which also excludes blank fields echo $_POST["First"]; if(isset($_POST["Middle"])){ echo $_POST["Middle"]; } echo $_POST["Last"]; I am currently creating a form and I want to populate a drop down selection menu with data from two fields in a form. For example, I want it to pull the first and last name fields from a database to populate names in a drop down menu in a form. I want the form to submit to the email address of the person selected in the drop down. Is this possible to do? The email is already a field in the record of the person in the database. Can anyone give me some pointers or advice on how I should go about setting up the "Select" box drop down? I am not sure how to code it to do what I am wanting. Any links to relevant help would be appreciated too. Thanks in advance! Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Man, I'm having a rough week with questions--if you're following at home. Basically matching a Coach's first and last name to another table, which if matched will yield information about that coach's team. Code: [Select] // or get user by username $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; $current_id = $current_user->ID; echo '<div class="contact_form">'; echo $current_first . ' ' . $current_last .' :: '; $query = "SELECT * FROM schools WHERE coachFirst='".$current_first."' AND coachLast='".$current_last."'"; $result = mysql_query ($query); if(!$result) { echo 'There is not a match for your name.'; } else { while($school= mysql_fetch_array($result)) { echo $school['school'] . ' ' . $school['id']; include(ABSPATH ."wp-content/plugins/my-team/form.php"); } echo '</div>'; echo '<div class="roster">'; include(ABSPATH ."wp-content/plugins/my-team/roster.php"); echo '</div>'; } Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! Hi all, I have this: Code: [Select] <?php session_start(); include('login/functions.php'); $username = $_SESSION['username']; $check = mysql_query("SELECT email FROM user_profile WHERE username = '$username'"); $a = mysql_fetch_field($check); if(empty($a)) { header('Location: complete.php'); } ?> However if the field is empty, ie no email address for user then nothing happens? Am going about this the right way? Cheers I have a number of fields to display on a page, from a mysql query, some fields are empty, some not. depends on what they choose on the original form. I am trying to display on the form results on a page formatted using the below: If the mysql field is empty, display an unchecked check box next to the result. If there is data in the field display a check box ticked. What can i do to achieve this, can you point me in the right direction? Results page using echo: </TD><TD>Options: <input type='checkbox' CHECKED>". $row[17]. " </TD> = is not empty field </TD><TD>Options: <input type='checkbox' UNCHECKED>". $row[17]. " </TD> = emtpy ,mysql field </TD><TD>Options: <input type='checkbox' CHECKED>". $row[18]. " </TD> = not empty mysql field from query </TD><TD>Options: <input type='checkbox' UNCHECKED>". $row[18]. " </TD> = Empty field in mysql I am trying to show Rows 1 to 16 to display normally, rows 17 to 30 use the above logic. There are about 30 fields to display like this, the others are required fields and are displayed no matter what. Hi all I have a pice of code that I want to only show the image if it's empty: Code: [Select] <?php if(!empty($node->field_img['und'][0]['filename'])); { ?> <li><img src="http://mysite.co.uk/sites/default/files/brand-images/<?php print $node->field_img['und'][0]['filename']; ?>" style="max-width:270px; text-align:center;" /></li> <?php } ?> However, it shows an image placeholder (Red cross) even when it's empty? Many thanks for your help Pete Ok so i have registration page on my webs but i didn't work on empty fields so how could i check all fields? Code: [Select] //if no name if(!$name){ $error = "Username missing."; } //if no pass if($pass == false){ $error = "$error,Password missing"; } //if no pass conf if($pass_conf == false) { $error = "$error,Pass conf missing."; } //if no email if($email == false){ $error = "$error,Email missing."; } //pass conf if($pass != $pass_conf){ $error = "$error,Passwords do not match."; } echo "<script>alert('$error');</script>;"; //header("Location: register.php"); My script gives same results every time (even if i fill any of fields)...also if i un-comment header command it wont show alert..it just reloads the page So can anyone help me with this? Thanks.. Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks below is my mail code. I am not sure what I am doing wrong. It works in outlook every once in awhile. Code: [Select] $fileatt = "/srv/www/##/####/files/"; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = "license.bin.".$num; // Filename that will be used for the file as the attachment $email_from = "sales@email.com"; // Who the email is from $email_subject = "email. License"; // The Subject of the email $email_message = "Please download file."; // Message that the email has in it $email_to = $email; // Who the email is too $headers = "From: ".$email_from; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n"; $file = fopen($fileatt,'rb'); $fileinfo = fread($file,filesize($fileatt)); fclose($file); $fileinfo = chunk_split(base64_encode($fileinfo)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $fileinfo . "\n\n" . "--{$mime_boundary}\n"; Can anyone see why I am having this issue? Hey guys i have a query echo (empty($row['deal'])? "empty": "not empty"); //result not empty but i need it to show the "not empty" if its "deal". by default it is a "1" when i select the row to be a deal it updates the table and inserts "Deal". Can anyone tell me the best way to handle empty search field on a mysql Query? The query below if $name is left blank but the other fields are filled it shows no results, currently i use if.... else.... but that means i have a lot of code replicated, is there a better way? $sql = "SELECT private.username, se.age, se.ro, se.suc, se.bu, se.fu, com.in, com.ol, se.di, se.bo, se.uin FROM Reg_Profile_public AS se INNER JOIN Reg_Profile_Private AS private USING (uin) INNER JOIN Reg_Profile_public_Com AS com USING (uin) WHERE se.age BETWEEN '$low' AND '$high' AND se.ro=''$name"; I see some of the fields in mysql show NULL and some are just empty, wonder what is the difference, is empty field still NULL? |