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条)

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题