Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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
在数据库php中插入Url最后2个字符_Php_Url_Path_Insert - Fatal编程技术网

在数据库php中插入Url最后2个字符

在数据库php中插入Url最后2个字符,php,url,path,insert,Php,Url,Path,Insert,我正在尝试将Url的最后2个字符插入到我的数据库中。每次插入时都需要一些数字,如“2147483647”。如何插入正确的Url的最后2个字符。 “$array=json_decode(stripslashes($_POST['data'])) 对于($i=0,$l=sizeof($array);$i

我正在尝试将Url的最后2个字符插入到我的数据库中。每次插入时都需要一些数字,如“2147483647”。如何插入正确的Url的最后2个字符。 “$array=json_decode(stripslashes($_POST['data']))

对于($i=0,$l=sizeof($array);$i<$l;$i++){ $obj=$array[$i]

if($obj->{'leaf'} == true){
    $leaf = 1;
} else{
    $leaf = 0;
}

if($obj->{'parentId'} == null){
    $parentID = 'null'; 
} else{
    $parentID = $obj->{'parentId'};
}

if($obj->{'Duration'}==''){
    $duration = 0;
} else{
    $duration = $obj->{'Duration'};
}




$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

$gantt_id = substr(strrchr($url, '='), 1);
/*if($obj->{'gantt_id'}==null){
    $gantt_id = 0;
} else{
    $gantt_id = $obj->{'gantt_id'};
}
*/
$q = 'INSERT INTO j_gantt_tasks SET Name = "'.$obj->{'Name'}.'", StartDate = "'.$obj->{'StartDate'}.'", EndDate = "'.$obj->{'EndDate'}.'",
      Duration = "'.$obj->{'Duration'}.'", DurationUnit = "'.$obj->{'DurationUnit'}.'", PercentDone = "'.$obj->{'PercentDone'}.'", Cls = "'.$obj->{'Cls'}.'", gantt_id="'.$gantt_id.'",
      parentId = "'.$obj->{'parentId'}.'"';

$r = mysql_query($q);
if(!$r){
    echo db_error($q);
}

$obj->{'id'} = mysql_insert_id();
} echo json_encode($array);'

试试看

$url = (!empty($_SERVER['HTTPS'])) ?
     "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : 
     "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];


$last2 = substring($url,-2);