我有一个代码,可以在特定数据库的每个表中插入数据。我运行它后出现此错误

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

我检查了输入错误的代码,但仍然看不到任何错误,可能是循环错误引起的

这是我的密码

$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)
  }
}

最佳答案

过了一会儿,您错过了半冒号

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


另外,建议不要使用mysql_*,因为不要使用它们,而应使用PDO防止sql注入。请参考to my answer here我已经在那详细解释了。

10-01 04:04
查看更多