angel1987 Posted May 27, 2010 Share Posted May 27, 2010 I need some help here. Basically i am accepting contact information from the user and there are some mandatory fields and some are not. So if user does not fill up these optional form fields then i want the PHP script to enter "Not Mentioned" in the database so when i view the submitted data i see "Not Mentioned" in front of respective labels. I tried my way through simple if else but it was not working. Here is the PHP script for adding in database. I am using Client side Javascript for validating other mandatory fields. <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); @mysql_select_db("contactms", $con); $sql="INSERT INTO contacts (fname, lname, email, website, mobile, work, home, address, country, city, addedby) VALUES ('$_POST[txtfirstname]','$_POST[txtlastname]','$_POST[txtemail]','$_POST[txtwebsite]','$_POST[txtmobile]','$_POST[txtwork]','$_POST[txthome]','$_POST[txtaddress]','$_POST[txtcountry]','$_POST[txtcity]','$_POST[txtaddedby]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); header("location:manage.php"); ?> Please help, Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/203058-how-to-enter-alternative-text-in-database-if-form-fields-are-blank/ 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.