0

im using php and mysql

php code:

foreach($form1 as $value)
{ 

    if($value!='')
    {   
        echo $query="insert into group_mapping('mid','gid','client_id') values('$value','".$_REQUEST['gid']."','".$_REQUEST['userid']."');";
        mysql_query($query);
    }
}

when I run the query manually it inserts right, but using php code value of 'client_id' going (NULL), mid and gid inserting correctly.

no mysql error, i have also tried echoing the query and its fine.

4

1 回答 1

0

Try adding some debug info into your script for example: Also you shouldn't have echo in the line: echo $query="insert....

<?
if($_REQUEST['gid']!=''&&$_REQUEST['userid']!='')
{
    foreach($form1 as $value)
    {
        if($value!=''))
        {
            $query="insert into group_mapping('mid','gid','client_id') values('$value','".$_REQUEST['gid']."','".$_REQUEST['userid']."');";
            if(mysql_query($query))
            {
                echo 'Query OK: '.$query.'<br>';
            }else{
                echo 'Query Problem: '.$query.'<br>';
                echo mysql_error().'<br>';
            }
        }else{
            echo 'Value is blank<br>';
        }
    }
}else{
    echo '$_REQUEST[gid] or $_REQUEST[userid] missing<br>';
}
?>
于 2012-07-29T08:24:01.543 回答