Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用php从excel导入和验证数据_Javascript_Php_Jquery_Html_Excel - Fatal编程技术网

Javascript 使用php从excel导入和验证数据

Javascript 使用php从excel导入和验证数据,javascript,php,jquery,html,excel,Javascript,Php,Jquery,Html,Excel,在使用PHP进入数据库之前,我一直在尝试导入和验证excel数据。代码应该从excel加载,并在PHP验证(如检查电子邮件验证)后插入到数据库中。如果出现问题,它将在一个表(带有输入框)中显示错误记录,右侧有一个div指示错误。我的问题是,它只显示最后一条有错误的记录,即使有多条错误记录。第二个问题是错误消息未显示在右侧div中 $objPHPExcel=PHPExcel_IOFactory::load($uploadfile); foreach ($objPHPExcel->getWo

在使用PHP进入数据库之前,我一直在尝试导入和验证excel数据。代码应该从excel加载,并在PHP验证(如检查电子邮件验证)后插入到数据库中。如果出现问题,它将在一个表(带有输入框)中显示错误记录,右侧有一个div指示错误。我的问题是,它只显示最后一条有错误的记录,即使有多条错误记录。第二个问题是错误消息未显示在右侧div中

 $objPHPExcel=PHPExcel_IOFactory::load($uploadfile);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) 
{

    $highestRow=$worksheet->getHighestRow();
    $nm = 1;
    $redo=0;
    for ($row=2; $row<=$highestRow;$row++)
    {  


        $company_name=mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(0,$row)->getValue());
        $contact_person= mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(1,$row)->getValue());
        $email=mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(2,$row)->getValue());
        $location=mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(3,$row)->getValue());
        $type=mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(4,$row)->getValue());
        $sector=mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(5,$row)->getValue());
        $legaility=mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(6,$row)->getValue());




        $html="<tr>";
        $html.='<td><input name="c_name" value="'.$company_name.'"></td>';
        $html.='<td><input name="cp" value="'.$contact_person.'"></td>';
        $html.='<td><input name="email"  value="'.$email.'" id="mail_'.$nm.'" onClick="getStates(this.value);"></td>';
        $html.='<td>'.$location.'</td>';
        $html.='<td><input name="type" value="'.$type.'"></td>';
        $html.='<td><input name="sector" value="'.$sector.'"></td>';
        $html.='<td><input name="legal" value="'.$legaility.'"></td>';
        $html.='<td width="10"><div id="results_'.$nm.'">here'.$nm.'</div></td>';
        $html.='</form>';
        $html.="</tr>";


        $email = filter_var($email, FILTER_SANITIZE_EMAIL);
        $chk_email= mysqli_query($con,"SELECT * FROM `company` WHERE `email`='$email'") or die("didnt chk email");
        $chk_nm=mysqli_num_rows($chk_email);


        if (filter_var($email, FILTER_VALIDATE_EMAIL) == true) 
                {
                    if ($chk_nm == 1)
                        {
                            $redo= $redo+1;
                        }
                        else
                        {
                    $ins_imp=mysqli_query($con,"INSERT INTO `company`(`ID`, `c_name`, `cp`, `email`, `status`, `location`, `Active`, `type`, `sector`, `legality`) VALUES
                        ('', '$company_name', '$contact_person', '$email', '', 'Ethiopia', 'active', '$type', '$sector', '$legaility')
                        ") or die("didnt enter data:".$email);
                    $html="";
                     }

                }
                else 
                {
                    echo '<script>$("results_'.$nm.'").html("error_log(message)")</script>';
                    echo 'error'.$nm;
                }

        $nm++;





    if ($row==$highestRow)
        { 
            if ($redo > 0)
                {
                echo "<br />There were ".$redo." records rejected becase they were already in the database.";
                }
        }



    }
}
$objPHPExcel=PHPExcel\u IOFactory::load($uploadfile);
foreach($objPHPExcel->getWorksheetIterator()作为$worksheet)
{
$highestRow=$worksheet->getHighestRow();
$nm=1;
$redo=0;
对于($row=2;$rowGetCellByColumnRow(0,$row)->getValue());
$contact\u person=mysqli\u real\u escape\u string($con,$worksheet->getCellByColumnRow(1,$row)->getValue());
$email=mysqli\u real\u escape\u string($con,$worksheet->getCellByColumnRow(2,$row)->getValue());
$location=mysqli\u real\u escape\u string($con,$worksheet->getCellByColumnRow(3,$row)->getValue());
$type=mysqli\u real\u escape\u string($con,$worksheet->getCellByColumnRow(4,$row)->getValue());
$sector=mysqli\u real\u escape\u string($con,$worksheet->getCellByColumnRow(5,$row)->getValue());
$legaility=mysqli\u real\u escape\u string($con,$worksheet->getCellByColumnRow(6,$row)->getValue());
$html=“”;
$html.='';
$html.='';
$html.='';
$html.=''.$location';
$html.='';
$html.='';
$html.='';
$html.='here'.$nm';
$html.='';
$html.=”;
$email=filter\u var($email,filter\u SANITIZE\u email);
$chk_email=mysqli_query($con,“从`company`中选择*,其中`email`='$email'))或die(“didnt chk email”);
$chk_nm=mysqli_num_行($chk_email);
if(filter\u var($email,filter\u VALIDATE\u email)==true)
{
如果($chk_nm==1)
{
$redo=$redo+1;
}
其他的
{
$ins\u imp=mysqli\u query($con,“插入公司”(`ID`、`c\u name`、`cp`、`email`、`status`、`location`、`Active`、`type`、`sector`、`validity`)值
(“$company\u name”、“$contact\u person”、“$email”、“埃塞俄比亚”、“活动”、“$type”、“$sector”、“$legaility”)
)或死亡(“未输入数据:.$email);
$html=“”;
}
}
其他的
{
echo“$”(“results.$nm.”)html(“error_log(message)”);
回波“错误”。$nm;
}
$nm++;
如果($row==$highestRow)
{ 
如果($redo>0)
{
echo“
有“$redo.”记录被拒绝,因为它们已经在数据库中了。“; } } } }