I want vendor_code to be VHSJS050814 where VH is the prefix, S is the first letter of form data 'city' and JS is the first letter of 'first_name' and 'last_name' of form data and 050814 is the currrent date. My php codes is furnished below. When I submit the form, I am not getting any data saved in Vendor_code in the database but other fields are getting saved. Please can anyone help me where I am going wrong?
HTML FORM:
<form action="process.php" method="post" name="form1" id="form1" class="register" enctype="multipart/form-data">
<fieldset class="row1">
<legend>SECTION 1: MEMBER CONTACT DETAILS
</legend>
<p>
<label>Title *
</label>
<select class="title" name="title">
<option>
</option>
<option>Mr.
</option>
<option>Mrs.
</option>
<option>Miss.
</option>
<option>Ms.
</option>
</select>
<label>
</label>
<input type="hidden" name="date_of_joining" value="<?php echo date("d.m.y");?>"/>
</p>
<p>
<label>First Name *
</label>
<input type="text" name="first_name"/>
<label>
</label>
<input type="hidden" name="vendor_code" value=""/>
</p>
<p>
<label>Last Name *
</label>
<input type="text" name="last_name"/>
<label>phone 1
</label>
<input type="text" name="phone1"/>
</p>
<p>
<label>Date of Birth
</label>
<input placeholder="mm-dd-yy" type="text" name="dob"/>
<label>phone 2
</label>
<input type="text" name="phone2"/>
</p>
<p>
<label>Address *
</label>
<input type="text" class="long" name="address"/>
<label>Mobile 1 *
</label>
<input type="text" name="mobile1"/>
</p>
<p>
<label>State/City *
</label>
<input type="text" class="long" name="city"/>
<label>Mobile 2
</label>
<input type="text" name="mobile2"/>
</p>
<p>
<label>Post Code *
</label>
<input type="text" name="postal_code"/>
<label>Email 1 *
</label>
<input type="text" class="long" name="email1"/>
</p>
<p>
<label>Country *
</label>
<input type="text" name="country"/>
<label>Email 2
</label>
<input type="text" class="long" name="email2"/>
</p>
<p>
</fieldset>
<fieldset class="row1">
<legend>SECTION 2: MEMBER ADDITIONAL DETAILS
</legend>
<p>
<label>Company Name *
</label>
<input type="text" name="company_name"/>
<label>Company Details
</label>
<input placeholder="Please mention" type="text" name="company_details"/>
</p>
<p>
<label>Company Address *
</label>
<input type="text" class="long" name="company_address"/>
<label>Area of Product *
</label>
<input placeholder="you deal into e.g. Womens Wear" type="text" class="long" name="area_of_products"/>
</p>
<p>
<label>Website
</label>
<input value="http://www." type="text" name="website"/>
<label>Nationality
</label>
<input type="text" class="long" name="nationality"/>
</p>
<p>
<label>Country of Res.
</label>
<input type="text" name="country_of_res"/>
<label>Member Type
</label>
<input type="text" class="long" name="member_type"/>
</p>
<p>
<label>Identity Proof
</label>
<select name="id_proof">
<option>
</option>
<option>Voter ID
<option>Passport
<option>Adhaar Card
</option>
</select>
<input name="file_idproof" type="file"/>
</p>
</fieldset>
<fieldset class="row4">
<p class="agreement">
<input type="checkbox" value="" name="policies"/>
<label>* I accept the <a href="required/t&c.htm?KeepThis=true&TB_iframe=true&height=500&width=600" class="thickbox" title="Terms & Policies">Terms and Policies</a></label>
</p>
</fieldset>
<div><button name="submit" class="button">Register »</button></div>
<input type="hidden" name="MM_insert" value="form1" />
</form>
And the code for process.php is here:
<?php require_once('connections/formsqlconnection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$w1=$_POST['city'][0];
$w2=$_POST['first_name'][0];
$w3=$_POST['last_name'][0];
$date = date("dmy");
$vendor_code = "VH" + $w1 + $w2 + $w3 + $date;
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO vendor_details (vendor_code, date_of_joining, title, first_name, last_name, dob, address, city, postal_code, country, phone1, phone2, mobile1, mobile2, email1, email2, company_name, company_details, company_address, area_of_product, website, nationality, country_of_res, member_type, id_proof, file_idproof) VALUES ($vendor_code, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['vendor_code'], "text"),
GetSQLValueString($_POST['date_of_joining'], "text"),
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['first_name'], "text"),
GetSQLValueString($_POST['last_name'], "text"),
GetSQLValueString($_POST['dob'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['postal_code'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['phone1'], "text"),
GetSQLValueString($_POST['phone2'], "text"),
GetSQLValueString($_POST['mobile1'], "text"),
GetSQLValueString($_POST['mobile2'], "text"),
GetSQLValueString($_POST['email1'], "text"),
GetSQLValueString($_POST['email2'], "text"),
GetSQLValueString($_POST['company_name'], "text"),
GetSQLValueString($_POST['company_details'], "text"),
GetSQLValueString($_POST['company_address'], "text"),
GetSQLValueString($_POST['area_of_product'], "text"),
GetSQLValueString($_POST['website'], "text"),
GetSQLValueString($_POST['nationality'], "text"),
GetSQLValueString($_POST['country_of_res'], "text"),
GetSQLValueString($_POST['member_type'], "text"),
GetSQLValueString($_POST['id_proof'], "text"),
GetSQLValueString($_FILES['file_idproof'], "text"));
mysql_select_db($database_formsqlconnection, $formsqlconnection);
$Result1 = mysql_query($insertSQL, $formsqlconnection) or die(mysql_error());
$insertGoTo = "confirm.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>