-3

my problem is that the value in array "Session name" can't be insert into table.Into the array of 'session name[]' value cannot insert into the table row.the code is as given below.please help me to solve my problem.

if(isset($_POST['submit']))
{
    if(isset($_POST['type']))
    {
        $prid=clean($_POST['type']);
    }

    if(isset($_POST['Introduction']))
    {
    $Introduction=clean($_POST['Introduction']);
    }

    if(is_array($_POST['Sessionname']))
    {
        $Sessionname=$_POST['Sessionname'];
        $sscount=count($Sessionname);   
    }

    if(is_array($_POST['duration']))
    {
        $duration=$_POST['duration'];
        $durcount=count($duration); 
    }




        for($i = 0;$i<=$durcount; $i++)
        {

            if($i==0)
            {
    $sql="INSERT INTO packages(prid,session_name,duration) VALUES 
    (
    '$prid',
    '$Introduction',
    '$duration[$i]'
    )";

            }
        else if($i>0)
                {
                    $j=$i-1;

                        for($j = 0;$j<=$sscount; $j++)
                        {

    $sql="INSERT INTO packages(prid,session_name,duration) VALUES 
    (
    '$prid',
    '$Sessionname[$j]',
    '$duration[$i]'
    )";

i want output in my table is like below :


pkid  prid       session_name          duration

 1      1    Introduction Session     15 minutes
 2      1           Session2          45 minutes
 3      1           Session3          30 minutes
 4      1           Session4           5 minutes
4

2 回答 2

0

Try to change your queries into these:

$sql="INSERT INTO packages(prid,session_name,duration) VALUES 
(
'$prid',
'$Introduction',
'".$duration[$i]."'
)";

$sql="INSERT INTO packages(prid,session_name,duration) VALUES 
(
'$prid',
'$Sessionname',
'".$duration[$i]."'
)";
于 2013-10-31T07:30:40.283 回答
0

Try to put $duration[$i] value into $d variable and put $d into your insert query. Same as $Sessionname[$j].

for($i = 0;$i<=$durcount; $i++)
        {
           $d=$duration[$i];

            if($i==0)
            {
    $sql="INSERT INTO packages(prid,session_name,duration) VALUES 
    (
    '$prid',
    '$Introduction',
    '$d'
    )";

            }
        else if($i>0)
                {
                    $j=$i-1;

                        for($j = 0;$j<=$sscount; $j++)
                        {
    $s_name=$Sessionname[$j];

    $sql="INSERT INTO packages(prid,session_name,duration) VALUES 
    (
    '$prid',
    '$s_name',
    '$d'
    )";
于 2013-10-31T07:39:03.750 回答