doufang1954 2014-10-15 05:56
浏览 31
已采纳

在表中插入数据时出错

I have a code which inserts data's in each tables in a specific database. After i run it this error come up

"Parse error: syntax error, unexpected '}', expecting ';' in C:\xampp\htdocs\Thesis\database\insertdata.php on line 37"

I check the codes for typo error but still i don't see any error on it maybe it is cause by a looping error

This is my Code

$db_name = array('morning_section_masterfile','evening_section_masterfile','afternoon_section_masterfile');
for($y=0;$y<=2;$y++)
{
   $db = mysql_select_db($db_name[$y],$connectDatabase);
   $tables = array('Pilot_Sections','Black_Sections');
     for($a=0;$a<=1;$a++)
     {
       //variable making
        $teacher = array ('Jane','Jeff','Liezeth','Loremas','Canada');
       $Default_Lname = 'Lorems';
       $Default_Fname = 'Vierzehn';
       $x=0;
       //Adding 30 students in one section
    do
    {
        for($i=0;$i<=30;$i++)
        {
            $section_teacher = $teacher[$x];
            $student_section = 'IT70'.$x.'E-C';
            $student_Lname = str_shuffle($Default_Lname);
            $student_Fname = str_shuffle($Default_Fname);
            $table = $tables[$a];
            $insert = "INSERT INTO $table (section_Teacher, student_Lastname, student_Firstname, student_Section) VALUES 
            ('{$section_teacher}','{$student_Lname}','{$student_Fname}','{$student_section}')";
            $insertdata = mysql_query($insert,$connectDatabase);
        }
    //check the number of students in a section section and adding another section
        if($i==31)
        {
            $x++;
            $i=0;
        }
    } while($x<=4)
  }
}
  • 写回答

3条回答 默认 最新

  • drt41563 2014-10-15 05:59
    关注

    You missed a semi colon after while

    do
        {
            for($i=0;$i<=30;$i++)
            {
                $section_teacher = $teacher[$x];
                $student_section = 'IT70'.$x.'E-C';
                $student_Lname = str_shuffle($Default_Lname);
                $student_Fname = str_shuffle($Default_Fname);
                $table = $tables[$a];
                $insert = "INSERT INTO $table (section_Teacher, student_Lastname, student_Firstname, student_Section) VALUES 
                ('{$section_teacher}','{$student_Lname}','{$student_Fname}','{$student_section}')";
                $insertdata = mysql_query($insert,$connectDatabase);
            }
        //check the number of students in a section section and adding another section
            if($i==31)
            {
                $x++;
                $i=0;
            }
        } while($x<=4);
    

    Also as an advice don't use mysql_* as they are deprecated, Use PDO instead to prevent sql injection. Please refer to my answer here I've explained it in detail there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)