0

i'm new to PHP and MySQL. I'm having issues with one of my mysqli_query functions. I have a database connection that works perfectly as the first half of my php file actually stores data into certain tables of the database.

The problem starts when i want to perform another query against the database. Here's the code:

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

When i run my form, my first error is the following: "Error while inserting data into member details table".

I don't understand why it's giving me an error. Any advice or suggestions would be appreciated. :)

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Gloire
  • 1,103
  • 3
  • 17
  • 26

1 Answers1

0

Don't output a fixed (and useless) error message: Have the DB tell you what you did wrong:

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

If you had that, you'd have been told about your syntax errors:

    $queryMember = "[..snip..], '$mobile_num', ,'$date_of_birth', '$studentNumber', '$id_number')";
                                             ^^^^
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Thank you very much Marc B. It actually simplified everything. I get a message that tells me that the member table does not exist and I know why. I actually changed the name of that table to memberdetails a few days ago and I forgot to update my php file. – Gloire Sep 17 '15 at 22:12