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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -