jmr3460 Posted March 12, 2009 Share Posted March 12, 2009 I have been working on a contact form and I just got the php working like I want it to. I am a 1 month newbee and I am a little excited to get this form to work. I have a contact form that will insert, update and delete record. I have created a script that creates a table with the field data is inserted into the td's. The only issue is that IE is not formatting the td's that are empty. I was wondering what code I could look at to insert an character when there is nothing entered from the form? Thanks for any help. jmr3460 Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/ Share on other sites More sharing options...
lonewolf217 Posted March 12, 2009 Share Posted March 12, 2009 are you saying it works in other browsers ? post some code Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783375 Share on other sites More sharing options...
jmr3460 Posted March 12, 2009 Author Share Posted March 12, 2009 What I am saying is that IE will not put a border around a cell that is empty. I was looking for a routine that would insert a X or a O into any field that is empty. maybe an if statement that would insert X in the record if there is nothing in the form field. Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783383 Share on other sites More sharing options...
redarrow Posted March 12, 2009 Share Posted March 12, 2009 you need to learn css or use inline css to get the height and width working. height does not exist in html properly. Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783384 Share on other sites More sharing options...
lonewolf217 Posted March 12, 2009 Share Posted March 12, 2009 use whatever method you have for retrieving data to put into fields that aren't empty. then check if its empty. if the string/item/whatever is empty, just echo whatever you want into the field Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783386 Share on other sites More sharing options...
samshel Posted March 12, 2009 Share Posted March 12, 2009 if you would have posted teh code, you would have got what u want in 1 reply Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783388 Share on other sites More sharing options...
djlee Posted March 12, 2009 Share Posted March 12, 2009 Some browser engines simply like to ignore styles on empty cells (an older version of FF used to do it not that i ever experienced it). Sometimes the best thing to do is just insert in empty cells, which to a browser is valid text and should format correctly. But as samshel said, post the code you've done and someone will be able to provide a much clearer answer Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783394 Share on other sites More sharing options...
jmr3460 Posted March 12, 2009 Author Share Posted March 12, 2009 Thanks for all the replies. I have already done some inline css. <?php $host = 'localhost'; $username = 'simplic5_jmr3460'; $password = ''; $database ='simplic5_contacts'; mysql_connect($host, $username, $password); mysql_select_db($database); $mysql_query_error = ''; function query($mysql_query){ global $mysql_query_error; $data = mysql_query($mysql_query); $mysql_query_error .= $mysql_query.'<br/>'; if (mysql_errno() !=0){ $mysql_query_error .= '<strong>Query failed: error# '.mysql_errno(). ' -- ' .mysql_error().'</strong><br/>'; } return $data; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="keywords" content="XTML 1.0, simplicityworks.org"/> <meta name="Discription" content="Simple XHTML page for SimplicityWorks PHP"/> <meta name="Author" content="Mark R."/> <title>SimplicityWorks PHP</title> <link rel="stylesheet" type="text/css" href="css/php.css" title="stylesheet"/> <style type="text/css"> td {padding:5px;border:solid 1px black;} span td {padding:2px;margin:0;border:solid 1px red;} </style> </head> <body> <h1 style="text-align:center;">Family Contacts Page</h1> <div style="position:relative;margin:0 auto;"> <?php $relationship = $_POST['relationship']; $alive = $_POST['alive']; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $hphoneArea = $_POST['hphoneArea']; $hphoneNum = $_POST['hphoneNum']; $cphoneArea = $_POST['cphoneArea']; $cphoneNum = $_POST['cphoneNum']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; $notes = $_POST['notes']; $postId = $_POST['id']; if (isset($_POST['submit'])){ if ($_POST['submit'] == 'Save'){ query("INSERT INTO family(id,relationship,alive,fname,lname,address,city,state,zip,hphoneArea,hphoneNum,cphoneArea,cphoneNum,email1,email2,notes) VALUES ('$id','$relationship','$alive','$fname','$lname','$address','$city','$state','$zip','$hphoneArea','$hphoneNum','$cphoneArea','$cphoneNum','$email1','$email2','$notes')"); }else if(isset($_POST['submit'])){ if ($_POST['submit'] == 'Save Edits'){ query("UPDATE family SET relationship='$relationship',alive='$alive',fname='$fname',lname='$lname',address='$address',city='$city',state='$state',zip='$zip',hphoneArea='$hphoneArea',hphoneNum='$hphoneNum',cphoneArea='$cphoneArea',cphoneNum='$cphoneNum',email1='$email1',email2='$email2',notes='$notes' WHERE id='$postId'"); } } } if (isset($_GET['action'])){ if ($_GET['action'] == 'delete'){query('DELETE FROM family WHERE id='.$_GET['id']); } else if ($_GET['action'] == 'edit'){ $infos = query("SELECT * FROM family WHERE id=".$_GET['id']); while($info = mysql_fetch_assoc($infos)){ $info_id = $info['id']; $info_relationship = $info['relationship']; $info_alive = $info['alive']; $info_fname = $info['fname']; $info_lname = $info['lname']; $info_address = $info['address']; $info_city = $info['city']; $info_state = $info['state']; $info_zip = $info['zip']; $info_hphoneArea = $info['hphoneArea']; $info_hphoneNum = $info['hphoneNum']; $info_cphoneArea = $info['cphoneArea']; $info_cphoneNum = $info['cphoneNum']; $info_email1 = $info['email1']; $info_email2 = $info['email2']; $info_notes = $info['notes']; print('<form method="POST" action="family.php"> <table style="margin-bottom:0;"> <tr><td><input type="text" name="id" value="'.$info_id.'" disables="true"/></td></tr> <tr> <td>Relationship:</td><td><input type="text" name="relationship" value="'.$info_relationship.'" /></td> </tr> <tr> <td>Alive:</td> <td>Yes <input type="radio" name="alive" value="'.$info_alive.'" checked/> No <input type="radio" name="alive" value="'.$info_alive.'" /></td> </tr> <tr><td>First Name:</td><td><input type="text" name="fname" value="'.$info_fname.'" /></td></tr> <tr><td>Last Name:</td><td><input type="text" name="lname" value="'.$info_lname.'" /></td></tr> <tr><td>Address:</td><td><input type="text" name="address" value="'.$info_address.'" /></td></tr> <tr><td>City:</td><td><input type="text" name="city" value="'.$info_city.'" /></td></tr> <tr><td>State:</td><td><input type="text" name="state" value="'.$info_state.'" /></td></tr> <tr><td>Zip:</td><td><input type="text" name="zip" value="'.$info_zip.'" /></td></tr> <tr><td>Home Phone Area Code:</td><td><input type="text" name="hphoneArea" value="'.$info_hphoneArea.'" /></td></tr> <tr><td>Home Phone Number:</td><td><input type="text" name="hphoneNum" value="'.$info_hphoneNum.'" /></td></tr> <tr><td>Cell Phone Area Code:</td><td><input type="text" name="cphoneArea" value="'.$info_cphoneArea.'" /></td></tr> <tr><td>Cell Phone Number:</td><td><input type="text" name="cphoneNum" value="'.$info_cphoneNum.'" /></td></tr> <tr><td>Main Email:</td><td><input type="text" name="email1" value="'.$info_email1.'" /></td></tr> <tr><td>2nd Email:</td><td><input type="text" name="email2" value="'.$info_email2.'" /></td></tr> </table> <table style="margin-top:0;padding-top:0;"> <tr> <td style="vertical-align:top;" wrap="hard">Notes:</td> <td><textarea name="notes" value="'.$info_notes.'"></textarea></td> <td><input type="submit" name="submit" value="Save Edits" /> <input type="reset" name="reset" value="Reset" /></td> </tr> </table> </form>'); } } } ?> <pre> <form method="POST" action="family.php"> <table style="margin-bottom:0;"> <tr> <td>Relationship:</td><td><input type="text" name="relationship" /></td> </tr> <tr> <td>Alive:</td> <td>Yes <input type="radio" name="alive" value="yes" checked/> No <input type="radio" name="alive" value="no"/></td> </tr> <tr><td>First Name:</td><td><input type="text" name="fname" /></td></tr> <tr><td>Last Name:</td><td><input type="text" name="lname" /></td></tr> <tr><td>Address:</td><td><input type="text" name="address" /></td></tr> <tr><td>City:</td><td><input type="text" name="city" /></td></tr> <tr><td>State:</td><td><input type="text" name="state" /></td></tr> <tr><td>Zip:</td><td><input type="text" name="zip" /></td></tr> <tr><td>Home Phone Area Code:</td><td><input type="text" name="hphoneArea" /></td></tr> <tr><td>Home Phone Number:</td><td><input type="text" name="hphoneNum" /></td></tr> <tr><td>Cell Phone Area Code:</td><td><input type="text" name="cphoneArea" /></td></tr> <tr><td>Cell Phone Number:</td><td><input type="text" name="cphoneNum" /></td></tr> <tr><td>Main Email:</td><td><input type="text" name="email1" /></td></tr> <tr><td>2nd Email:</td><td><input type="text" name="email2" /></td></tr> </table> <table style="margin-top:0;padding-top:0;"> <tr> <td style="vertical-align:top;" wrap="hard">Notes:</td> <td><textarea name="notes"></textarea></td> <td><input type="submit" name="submit" value="Save" /> <input type="reset" name="reset" value="Reset" /></td> </tr> </table> </form> </pre> <table> <tr><th>ID</th> <th>Alive</th> <th>Relationship</th> <th>First Name</th> <th>Last Name</th> <th>Address</th> <th>City</th> <th>State</th> <th>Zip Code</th> <th>Home Phone Area</th> <th>Home Phone Number</th> <th>Cell Phone Area</th> <th>Cell Phone Number</th> <th>Main Email</th> <th>Other Email</th> <th>Notes</th></tr> <?php $contacts = query('SELECT * FROM family'); while($contact = mysql_fetch_assoc($contacts)){ print('<tr><td style="padding:1px;border:solid 1px red;">'.$contact['id'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['alive'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['relationship'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['fname'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['lname'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['address'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['city'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['state'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['zip'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['hphoneArea'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['hphoneNum'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['cphoneArea'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['cphoneNum'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['email1'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['email2'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;">'.$contact['notes'].'</td> <td style="margin:0;padding:1px;border:solid 1px red;"> <a href="family.php?action=delete&id='.$contact['id'].'">Delete</a> - <a href="family.php?action=edit&id='.$contact['id'].'">Edit</a></td></tr>'); } ?> </table> <? print('<div style="clear:both"></div><br/><br/>'.$mysql_query_error); ?> <br/><br/> </div> </body> </html> This is everything. This is also my first successful usable code. This code has not been validated yet. I am just starting my PHP and MySQL lessons. This is a little bit of instructions, a littlebit of PHP Freaks and a little bit on my part learning hoe to read error codes (Mostly learning to read error codes). I think that there are a few notices on that come up on my test environment here at home. jmr3460 Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783400 Share on other sites More sharing options...
samshel Posted March 13, 2009 Share Posted March 13, 2009 where ur populating all ur variables try doing this.. $info_id = ((trim($info['id']) != "") ? $info['id'] : " "); this code checks if the variable fetched from DB row has a value else assigns space to that variable. you can replace space with any char u like.. do it for all variables Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783436 Share on other sites More sharing options...
jmr3460 Posted March 13, 2009 Author Share Posted March 13, 2009 Thanks samshel you are my newest BFF. This worked on everything except my notes textarea. I read up on the trim function. What does the colin do? $info_email2 = $info['email2']; $info_email2 = ((trim($info['email2']) != "") ? $info['email2'] : "X"); $info_notes = $info['notes']; $info_notes = ((trim($info['notes']) != "") ? $info['notes'] : "X"); Email2 works good but notes is not doing anything. Did I do something wrong? I read up a little on the trim function. I read that it gets rid of whitespace in front and back. Your code trims notes if not assigned then $info_notes is set to whatever is set between the double quotes. Am I close? Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783474 Share on other sites More sharing options...
jmr3460 Posted March 13, 2009 Author Share Posted March 13, 2009 After further testing it seems that update form does not update nor does nor does my edit populate textarea. I am still looking. Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783492 Share on other sites More sharing options...
jmr3460 Posted March 13, 2009 Author Share Posted March 13, 2009 Could this be how I have my DB set up I have the textarea set as a varchar and not null. Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783497 Share on other sites More sharing options...
jmr3460 Posted March 13, 2009 Author Share Posted March 13, 2009 It appears that the edit link is where things are not working. Only on the notes field. I changed the textarea to a text box and everything works I am going to say it is working now I am going to be the only one to use it. Thanks so very much Quote Link to comment https://forums.phpfreaks.com/topic/149180-solved-filling-in-the-blanks/#findComment-783507 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.