Jump to content

How to enter alternative text in database if form fields are blank?


angel1987

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.