mysql - Accessing arrays created by explode function in php -
i'm beginner in php , mysql. pass string php ajax , split string after new lines. later assign each element in array variable. want pass variables mysql database.
please assume:
$q = "john \n doe \n 07589334009 \n john.doe@john.com";
here attempt:
$date = date('y/m/d h:i:s'); $q = $_request["q"]; $arr = explode(php_eol, $q); $name = $arr[0]; $surname = $arr[1]; $phone = $arr[2]; $email = $arr[3]; $sql = "insert `database`.`mytable` (`name`, `surname`, `phone`, `email`, `reg_date`, `valid`) values ('$name' , '$surname', '$phone', '$email', '$date', '1');"; $result = $conn->query($sql);
when check database see "johndoe07589334009john.doe@john.com" in name column. apart name , valid columns okay.
just try like
$arr = explode("\n", $q); $name = $arr[0]; $surname = $arr[1]; $phone = $arr[2]; $email = $arr[3];
explode using \n , remove spaces after exploding
Comments
Post a Comment