I have an issue in a PHP script which checks if the tax number has right company name on input some other form fields and insert into MySQL. What I want is to put some control code – maybe “select distinct formCompany from company where formCompany = “.$formCompany.” ” or some code which checks if taxid is given correctly for the name of company from input form. Does someone have idea of how to do that? Any example is welcome.
I have script which simply input data from form fields into MySQL db:
$db=mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$taxid=mysql_real_escape_string($_POST['taxid']);
$formCompany=mysql_real_escape_string($_POST['formCompany']);
$formOffice=mysql_real_escape_string($_POST['formOffice']);
$formBr=mysql_real_escape_string($_POST['formBr']);
$formContact=mysql_real_escape_string($_POST['formContact']);
//trim
$id=trim($id);
$taxid=trim($taxid);
$formCompany=trim($formCompany);
$formOffice=trim($formOffice);
$formBr=trim($formBr);
$formContact=trim($formContact);
if($_POST['taxid']==''||$_POST['formCompany']=='') {
echo '<p style="color: red">Input relevant data!<p>';
} else {
$sql = "INSERT INTO company (taxid, formCompany,formOffice,formBr,formContact) VALUES ('$taxid','$formCompany','$formOffice','$formBr', '$formContact')";
if(!$result = mysql_query($sql, $db)) {
echo "ERROR: ".mysql_error();
} else {
header("Refresh: 0; url=main.php");
}
}
First, add this code before the if statement
Then change this line
to
This code will prevent you from ending up with more than one company using one tax ID number.