I have a nested table where projects and students are stored called Proyecto_alumno, it has the function of registering students to the projects, the students and the projects are saved separately.
It happens that when enrolling students to a project, the project without knowing because in its title field is deleted, it remains empty, the project being saved before with all its fields in the database.
I leave the code with which I keep the students in the nested table with the ID of the selected project.
<?php
include 'conexion.php';
foreach ($_REQUEST['alum'] as $alumno_id)
{
$alumno = array('proy_id' => NULL, 'proy_id' => $_REQUEST['proy_id'], 'alum_id' => $alumno_id);
bd_proyecto_alumno_agregar($alumno);
}
header("Location: listado4.php");
exit;
Followed by the code that the students add "bd_proyecto_alumno_agregar"
function bd_proyecto_alumno_agregar($d)
{
$sql = sprintf("INSERT INTO
proyecto_alumno (proy_alum_id, proy_id, alum_id)
VALUES
('%s','%s','%s')",
$d['proy_alum_id'],
$d['proy_id'],
$d['alum_id']
);
$res = sql($sql);
$id = sql2value("SELECT LAST_INSERT_ID()");
return $id;
}
Project Table
CREATE TABLE 'proyecto' (
'proy_id' int(4) UNSIGNED NOT NULL,
'proy_deno' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
'plan_proy' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
'objg_proy' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
'obje_proy' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
'fech_insc' date NOT NULL,
'nomb_comu' varchar(50) COLLATE utf8_unicode_ci NOT NULL,
'resp_comu' varchar(50) COLLATE utf8_unicode_ci NOT NULL,
'parr_id' int(4) NOT NULL,
'deta' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
'esta_proy_id' int(1) NOT NULL,
'telf_inst' varchar(11) COLLATE utf8_unicode_ci NOT NULL,
'telf_resp' varchar(11) COLLATE utf8_unicode_ci NOT NULL,
'obsv_proy' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'proy_carr_id' int(2) NOT NULL
Student_Project_table
CREATE TABLE 'proyecto_alumno' (
'proy_alum_id' int(4) UNSIGNED NOT NULL,
'proy_id' int(5) UNSIGNED NOT NULL,
'alum_id' int(9) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
COMPLETE PUPIL REGISTRY FORM