Insert from 1 form into different tables.

I’m having a registration site, that looks like this:

[php]

Registrer nytt medlem Fornavn:
Etternavn:
Telefon:
Epost:
Postadresse:

Godkjent førstehjelpsprøve: checked="checked"<?php endif; ?> />
Videregående førsthjelp: checked="checked"<?php endif; ?> />

Vinter:
Vinter kurs C: checked="checked"<?php endif; ?> />
Vinter kurs B: checked="checked"<?php endif; ?> />
Vinter kurs A: checked="checked"<?php endif; ?> />

[/php] All the way down to value 20.

And it’s insert.php i’m having some problems with:
[php]<?php
$con = mysql_connect(“localhost”,“sql”,“password”) or die('Could not connect: ’ .mysql_error());
mysql_select_db(“sql”, $con) or die(mysql_error());

$fornavn = mysql_real_escape_string($_POST[‘fornavn’]);
$etternavn = mysql_real_escape_string($_POST[‘etternavn’]);
$telefon = mysql_real_escape_string($_POST[‘telefon’]);
$epost = mysql_real_escape_string($_POST[‘epost’]);
$adresse = mysql_real_escape_string($_POST[‘adresse’]);
$kurs = ($_POST[‘kurs’]);

$sql=“INSERT INTO folk (fornavn, etternavn, telefon, epost, adresse)
VALUES (’$fornavn’, ‘$etternavn’, ‘$telefon’, ‘$epost’, ‘$adresse’)”;

mysql_query($sql)
or die (‘Error updating folk’);

$inserted_id = mysql_insert_id();

foreach ($_POST[‘kurs’] as $kursid => $f) {
printf("(’%s’,’%s’),", $inserted_id, $kursid);
}

$sql_1=“INSERT INTO harkurs (personid, kursid)
VALUES (‘inserted_id’, ‘$kursid’)”;

mysql_query($sql_1)
or die (‘Error updating the kurs in harkurs’);

mysql_close($con);

echo “1 record added”;
?>[/php]

My database is 3 tables.
Table 1 (folk): ID, fornavn (firstname), etternavn (lastname), telefon (phone), epost (email), adresse (address).
Table 2 (kursnavn): kursnavnid (courses id), kursnavn (courses).
Table 3 (harkurs): personid (person id), kursid (courses id)

I’m trying to get all personal information into table 1. (works)
And taking the information from all the checkboxes into table 3.
With personid and course id.

Looks like you are already on the right track. What problem are you having?

Sponsor our Newsletter | Privacy Policy | Terms of Service