mysqli_query函数的问题

时间:2015-09-17 21:50:58

标签: php sql mysqli mysql-workbench

我是PHP和MySQL的新手。我遇到了一个mysqli_query函数问题。我有一个完美的数据库连接,因为我的php文件的前半部分实际上将数据存储到数据库的某些表中。

当我想对数据库执行另一个查询时,问题就开始了。这是代码:

// INSERT statements. 
$queryMember = "INSERT INTO member (surname, name, gender, email, telHome, telMobile, dob, studentNum, idNum) VALUES ('$sur_name', '$f_name', '$gender', '$email', '$tel_home', '$mobile_num', ,'$date_of_birth', '$studentNumber', '$id_number')";

$queryAddress = "INSERT INTO physicalDetails (houseNum, unitNum, streetAdd, suburb, city, province, code ) VALUES ('$house_number', '$unit_number', '$street_address', '$suburb_name', '$city_name', '$province_name', '$zip_code')";

$queryStaff = "INSERT INTO staff (staffID ) VALUES ('$staff_id')"; 

$queryStudent = "INSERT INTO student (major ) VALUES ('$student_major')"; 

// Statements that must query the database. 
$resultMember = mysqli_query($dbc, $queryMember) or die ('Error while inserting data into member details table');

$resultAddress = mysqli_query($dbc, $queryAddress ) or die ('Error while inserting data into member physical details table');

$resultStaff = mysqli_query($dbc, $queryStaff ) or die ('Error while inserting data into staff information table' );

$resultStudent = mysqli_query($dbc, $queryStudent ) or die ('Error while inserting data into student major details table');

mysqli_close($dbc);

当我运行表单时,我的第一个错误如下:"将数据插入成员详细信息表"时出错。

我不明白为什么它会给我一个错误。任何建议或意见将不胜感激。 :)

1 个答案:

答案 0 :(得分:0)

不要输出固定(且无用)的错误消息:请让DB告诉您错误的做法:

$resultMember = mysqli_query($dbc, $queryMember) or die (mysqli_error($dbc));
                                                          ^^^^^^^^^^^^

如果你有这个,你就会被告知你的语法错误:

    $queryMember = "[..snip..], '$mobile_num', ,'$date_of_birth', '$studentNumber', '$id_number')";
                                             ^^^^