add country

<?PHP
header(‘Cache-Control: no-cache, no-store, must-revalidate’); //HTTP/1.1
header(‘Expires: Sun, 01 Jul 2000 00:00:00 GMT’);
header(‘Pragma: no-cache’); //HTTP/1.0
include “conn.php”;
ob_start();
session_start();
$submit=$_POST['Submit'];
$c_name=$_POST['countryname'];
$cn=explode(“,”,$c_name);
$countryname=$cn[1];
$countrycode=$_POST['countrycode'];
$cc=$_POST['creditcart'];
$billme=$_POST['billmelater'];
$bankt=$_POST['banktransfer'];
$check=$_POST['check'];
$payuponrecive=$_POST['payuponrecive'];
$codrate=$_POST['codrate'];
$tax=$_POST['taxrate'];
$express=$_POST['express'];
// Product Image
$ftmp = $_FILES['countryimage']['tmp_name'];
$oname = $_FILES['countryimage']['name'];
$random=mt_rand(100,500);
$oname = $random.basename($oname);
$archivedir = ‘../flagimage/’.$oname;

//product icon
/*$ftmp2 = $_FILES['icon']['tmp_name'];
$oname2 = $_FILES['icon']['name'];
$random1=mt_rand(100,500);
$oname2 = $random1.basename($oname2);

$archivedir2 = ‘../upload_producticon/’.$oname2;
*/
if ($submit ==’Continue’)
{
$_SESSION['button']=’Continue’;

$checkcountry = mysql_query(“SELECT country_name FROM countries WHERE country_name=’$countryname’”);

$country_exist = mysql_num_rows($checkcountry);

if($country_exist > 0){
$err=”I’m sorry country you specified has already been taken.  Please pick another one.”;

}
if($err==”")
{
if($oname != “” )
{
if(move_uploaded_file($ftmp,$archivedir) )
{

echo $insert=mysql_query(“insert into countries (country_name,country_code,credit_cart ,bill_me_later ,bank_transfer,pay_by_check  ,pay_upon_received,country_image,cash_on_rate ,tax_rate) values (‘$countryname’,'$countrycode’,’ $cc’,'$billme’, ‘$bankt’,'$check’,'$payuponrecive’,'$oname’,'$codrate’,'$tax’)”);

}
else
{
$insert=mysql_query(“insert into countries (country_name,country_code,credit_cart ,bill_me_later ,bank_transfer ,pay_by_check ,pay_upon_received,cash_on_rate ,tax_rate) values (‘$countryname’,'$countrycode’,’ $cc’,'$billme’, ‘$bankt’,'$check’,'$payuponrecive’,'$codrate’,'$tax’)”) or die(mysql_error());

}
}
}

}
//echo mysql_error();
if($insert==1)
{
header(“Location: country.php”);
}

?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Add Country</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=”javascript” type=”text/javascript”>
function validate()
{
if(document.frm.countryname.value== 0)
{
alert(“Please Select country Name”);
//document.frm.bname.focus();
//document.frm.countryname.value=”";
document.frm.countryname.focus();
return false;
}
if(!isNaN(document.frm.countryname.value))
{
alert(“Please enter valid country name”);
document.frm.countryname.value=”";
document.frm.countryname.focus();
return false;
}

if(document.frm.countrycode.value == 0)
{
alert(“Please Select Country Code”);
document.frm.countrycode.value=”";
document.frm.countrycode.focus();
return false;
}
if (document.frm.creditcart.checked == false &&
document.frm.billmelater.checked == false &&
document.frm.banktransfer.checked == false &&
document.frm.check.checked == false &&
document.frm.payuponrecive.checked == false) {

alert(“Please select at least one checkbox.\n”);
return false;
}

if(document.frm.countryimage.value == 0)
{
alert(“Please Select Country Image”);
document.frm.countryimage.focus();
return false;
}

if(document.frm.creditcart.value == 0)
{
alert(“Please Select  Any one payment Detail”);
document.frm.subcat.focus();
return false;
}
if(document.frm.codrate.value == “”)
{
alert(“Please Select cash on delivery”);
document.frm.codrate.value=”";
document.frm.codrate.focus();
return false;
}
if(document.frm.taxrate.value == “”)
{
alert(“Please Select taxrate”);
document.frm.taxrate.value=”";
document.frm.taxrate.focus();
return false;
}

if(document.frm.express.value == 0)
{
alert(“Please Select Shipping Express “);
document.frm.express.value=”";
document.frm.express.focus();
return false;
}
document.frm.submit();
return true;
}
function isint(s)
{
var i=0;
for(i=0; i<s.length; i++)
{
var c=s.charAt(i);
if(((c <”0″) || (c > “9″))) return false;
}
return true;
}

function get_country_code()
{
var ccode = document.frm.countryname.value;
//alert(ccode);
document.frm.countrycode.value=ccode.substring(0,2);
}

</script>
</head>
<link rel=”stylesheet” href=”style.css” type=”text/css”>
<body>
<form name=”frm” method=”post” enctype=”multipart/form-data” action=”" onSubmit=”return validate();”>
<table border=”0″  bgcolor=”#990000″ align=”center” width=”100%” height=”575″ cellpadding=”3″ cellspacing=”1″>
<tr bgcolor=”#FFFFFF”>
<td height=”40″ align=”center” class=”style3″><?php include “leftmenu.php”; ?></td>
</tr>
<tr bgcolor=”#FFFFFF”>
<td>

<p>&nbsp;</p>
<table width=”55%” align=”center” cellpadding=”2″ cellspacing=”2″ border=”0″>

<tr bgcolor=”#FFFFFF” height=”50″>
<td height=”35″ colspan=”2″ align=”center” class=”style4″><font color=”red”><?php echo $err;?> </font></td>
</tr>
<tr bgcolor=”#CCCCCC” height=”50″>
<td height=”35″ colspan=”2″ align=”center” class=”style4″><span style=”font:”Times New Roman”" ><b>Countries And Payment Detail</b></span></td>
</tr>

<!– OLD CountryName and Code Row
<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Enter Country Name:</td>
<td width=”50%”>&nbsp;
<input type=”text” name=”countryname”></td>
</tr>

<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Enter Country Code:</td>
<td width=”50%”>&nbsp;
<input type=”text” name=”countrycode”></td>
</tr>
–>

<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Select Country Name:</td>
<td width=”50%”>&nbsp;
<select name=”countryname” onChange=”get_country_code();”>
<option value=”0″>Select Country</option>
<?php
$co_sql=”SELECT c_name, c_code FROM country_name order by c_name”;
$co_result=mysql_query($co_sql);
while($co_row=mysql_fetch_array($co_result))
{
?>
<option value=”<?php echo $co_row['c_code'].”,”.$co_row['c_name']; ?>”><?php echo $co_row['c_name']; ?></option>
<?php
}
?>
</select>
</td>
</tr>

<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Country Code:</td>
<td width=”50%”>&nbsp;
<input type=”text” name=”countrycode” value=”Select Country” readonly=”readonly”></td>
</tr>

<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Payment Select :</td>
<td width=”50%”>&nbsp;<input type=”checkbox” name=”creditcart” value=’1′ >&nbsp;Creditcart
<input type=”checkbox” name=”billmelater” value=’1′  >&nbsp;Bill Me Later
<input type=”checkbox” name=”banktransfer” value=’1′  >&nbsp;Bank Transfer
<input type=”checkbox” name=”check” value=’1′ >&nbsp;Check
<input type=”checkbox” name=”payuponrecive” value=’1′  > &nbsp;Pay Upon Receive</td>
</tr>

<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Enter Country Flag image:</td>
<td width=”50%”>&nbsp;
<input type=”file” name=”countryimage”></td>
</tr>

<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Enter Cash On Delivery Rate:</td>
<td width=”50%”>&nbsp;
<input type=”text” name=”codrate”></td>
</tr>

<tr bgcolor=”#DDDDDD” height=”25″ class=”style1″>
<td width=”50%” align=”right”>Enter Tax Rate:</td>
<td width=”50%”>&nbsp;
<input type=”text” name=”taxrate”></td>
</tr>

<!–  <tr bgcolor=”#DDDDDD” height=”40″ class=”style1″>
<td align=”right”>Enter Shipping Express </td>
<td align=”left”><label>
<input name=”express” type=”text” id=”express”>
</label></td>
<tr bgcolor=”#DDDDDD” height=”40″ class=”style1″>–>
<td colspan=”2″ align=”center”><input name=”Submit” type=”submit” value=”Continue”></td>
</table>
<p>&nbsp;</p></td>
</tr>
</table>

</form>
</body>
</html>

Leave a Comment