I have a weird issue that's driving me crazy. The first time I insert data into a mysql table, it works. It fails silently after that. This is the table:
$students =
'CREATE TABLE IF NOT EXISTS students (
student_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
nombre VARCHAR(255) NOT NULL,
apellido VARCHAR(255) NOT NULL,
natalicio INT NOT NULL,
cuil INT UNIQUE NOT NULL,
trabajador_teatro TINYINT NOT NULL,
ocupacion VARCHAR(255),
derivado_ministerio TINYINT NOT NULL,
ex_alumno TINYINT NOT NULL,
intereses VARCHAR(255),
matricula VARCHAR(255) NOT NULL,
estudios_formales VARCHAR(255),
domicilio VARCHAR(255),
mail VARCHAR(255) NOT NULL,
mail_confirmation_key VARCHAR(255) ,
created INT,
tel INT NOT NULL,
active TINYINT NOT NULL
)';
This is the method that inserts the data, remember, first insert works well:
/
/Insert user data
public function insertStudent($options, $db_object) {
$sql='INSERT INTO students (nombre, apellido, natalicio, cuil, trabajador_teatro, ocupacion,
derivado_ministerio, ex_alumno, intereses, matricula, estudios_formales, domicilio, mail, mail_confirmation_key,
created, tel, active)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
if (is_array($options) ) {
$nombre = $options['nombre'];
$apellido = $options['apellido'];
$natalicio = $options['natalicio'];
$cuil = $options['cuil'];
$trabajador_teatro = $options['trabajador_teatro'];
$ocupacion = $options['ocupacion'];
$derivado_ministerio = $options['derivado_ministerio'];
$ex_alumno = $options['ex_alumno'];
$intereses = $options['intereses'];
$estudios_formales = $options['estudios_formales'];
$domicilio = $options['address'];
$mail = $options['mail'];
$tel = $options['tel'];
}//End if
$mail_confirmation_key = $this->mailConfKey();
$date = new DateTime();
$created = $date->getTimestamp();
$active = 0;
$matricula = 'TAE'."-".ceil((substr($cuil, 4)+$created)/5);
/* Prepare statement */
$stmt = $db_object->prepare($sql);
if($stmt === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $db_object->error, E_USER_ERROR);
}//End if
/* Bind parameters. TYpes: s = string, i = integer, d = double, b = blob */
$stmt->bind_param('ssiiisiissssssiii',$nombre, $apellido, $natalicio, $cuil, $trabajador_teatro, $ocupacion, $derivado_ministerio,
$ex_alumno, $intereses, $matricula, $estudios_formales, $domicilio, $mail, $mail_confirmation_key, $created, $tel, $active);
/* Execute statement */
$stmt->execute();
echo $stmt->insert_id;
echo $stmt->affected_rows;
$stmt->close();
}//End insertStudent
There are no apache2 log errors. These are mysql logs, the first query that works, and the subsequent one that does not work.
First Query
61 Prepare INSERT INTO students (nombre, apellido, natalicio, cuil, trabajador_teatro, ocupacion,
derivado_ministerio, ex_alumno, intereses, matricula, estudios_formales, domicilio, mail, mail_confirmation_key,
created, tel, active)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
61 Execute INSERT INTO students (nombre, apellido, natalicio, cuil, trabajador_teatro, ocupacion,
derivado_ministerio, ex_alumno, intereses, matricula, estudios_formales, domicilio, mail, mail_confirmation_key,
created, tel, active)
VALUES ('Diego','Lopez',1395975600,20218976543,1,'Surfer',1,0,'Volar','TAE-280617849','primario','20 1122','test@test.com','jtvSRLYfU8uyiHVh6gPp',1394$
61 Close stmt
Second query
72 Prepare INSERT INTO students (nombre, apellido, natalicio, cuil, trabajador_teatro, ocupacion,
derivado_ministerio, ex_alumno, intereses, matricula, estudios_formales, domicilio, mail, mail_confirmation_key,
created, tel, active)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
72 Close stmt
72 Quit
I fetch data from $_POST and use it. It's just a beta, I know it's not properly sanitized.
$nombre = stripcslashes($_POST['nombre']);
$apellido = stripcslashes($_POST['apellido']);
$natalicio = $core->formatTimeToUs($_POST['birthday']);
$mail = $_POST['mail'];
$address = stripcslashes($_POST['address']);
$tel = stripcslashes($_POST['tel']);
$cuil = stripcslashes($_POST['cuil']);
$curso = stripcslashes($_POST['curso']);
$niv_educ = stripcslashes($_POST['niv_educ']);
$trabajador_teatro = stripcslashes($_POST['trabajador_teatro']);
$ocupacion = stripcslashes($_POST['ocupacion']);
$derivado_ministerio = stripcslashes($_POST['derivado_ministerio']);
$ex_alumno = stripcslashes($_POST['ex_alumno']);
$intereses = stripcslashes($_POST['intereses']);
$estudios_formales = stripcslashes($_POST['niv_educ']);
$student = new student();
$student_user_array = array('nombre'=>$nombre, 'apellido'=>$apellido , 'natalicio' => $natalicio, 'cuil'=>$cuil, 'mail' => $mail, 'address' => $address, 'tel' => $tel,
'curso'=>$curso, 'niv_educ'=>$niv_educ, 'trabajador_teatro' => $trabajador_teatro, 'ocupacion' => $ocupacion,
'ex_alumno' => $ex_alumno, 'intereses'=>$intereses, 'estudios_formales'=> $estudios_formales, 'derivado_ministerio'=>$derivado_ministerio);
$student->insertStudent($student_user_array, $conn);
Hope someone can point me in the right direction. Thanks in advance. Sebastian