我写了一个插入数据的函数,它工作得很好,直到上一个项目,但现在我面临问题,问题是数据插入两次。我试图打印查询,每件事都很好,没有循环。如果我从phpmyadmin
执行查询,那么它可以正常工作。
代码如下:
<?php
function insert($table,$headers,$data)
{
global $conn;
debug_print_backtrace();
$values = "'".implode("','",$data)."'";
$sql = "insert into ".$table."(".implode(",",$headers).") values(".$values.")";
echo $sql;
$res = mysqli_query($conn,$sql);
if($res)
return true;
else
return mysql_error();
}
include('controller.php');
error_reporting(E_ALL);
global $conn;
$email = check_email($_POST['email']);
$sub = explode(",", $_POST['suburb']);
$to = get("admin",'0');
//$fileName = implode(",", $fileName);
$headers = array('SM_ID','password','SM_key','Active','Block','SM_EID','C_ID','SM_Name','Email_ID','Mobile','Address','Suburb','PIN','State','Profile_Pic','Date');
$_SESSION['key'] = $key;
$rand = mt_rand(0, 32);
//$password = md5($rand.time());
$length = 10;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$password = '';
for ($i = 0; $i < $length; $i++) {
$password .= $characters[rand(0, $charactersLength - 1)];
}
//echo $password;
$check_eid = get_max('service_manager','SM_EID');
var_dump($check_eid);
/*$check_eid = $check_eid['0']['SM_EID'];//*/
$check_eid = explode("_", $check_eid);
//var_dump($check_eid['1']);
if(!$check_eid['1'])
$sm_eid = 100;
else
$sm_eid = $check_eid['1']+1;
$sm_eid = "SM_".$sm_eid;
//echo $sm_eid;
$key = md5($sm_eid.$_POST['email']);
$data = array('',md5($password),$key,'1','0',$sm_eid,$_POST['zone'],$_POST['name'],$_POST['email'],$_POST['phone'],mysqli_real_escape_string($conn,$_POST['address']),$sub['0'],$sub['1'],$_POST['state'],$_FILES["profile_pic"]["name"],date('d/m/Y h:i:s a', time()));
$insert = insert('service_manager',$headers,$data);
?>