Ik ben bezig met een project waarbij ik een id twee keer tegelijkertijd wil opslaan. heb hiervoor twee tabellen aangemaakt.
tabel 1:
id
name
tabel 2:
SID
Loc_Code
Het is de bedoeling dat in tabel 1 het id en naam opgeslagen word van het service, en in tabel 2 tegelijkertijd het service id on SID wordt opgelagen en onder Loc_code de geselecteerde waarde.
Hij slaat nu alleen de geselecteerde waarde, maar pakt het id niet mee uit tabel 1.
Kan iemand mij daarmee helpen?
Hieronder vindt je mijn code:
<html>
<head>
</head>
<body>
<?php
mysql_connect('localhost','root','');
mysql_select_db('services');
/* Generating the new ServiceID */
$query = "SELECT id FROM taxi_services ORDER BY id DESC LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
//Selecting locations
$count = mysql_num_rows($result);
?>
<?php
if(isset($_POST["savebtn"]))
{
//inserting the new service information
$id = $_GET['id'];
$name = $_POST["name"];
$query = "INSERT INTO taxi_services(id, Name) VALUES('', '$name')";
$result = mysql_query($query);
$checkbox1 = $_POST['chk1'];
for ($i=0; $i<sizeof($checkbox1);$i++) {
$query="INSERT INTO service_locations(SID,Loc_Code) VALUES('".$id."','".$checkbox1[$i]."')";
mysql_query($query) or die(mysql_error());
}
?>
<script type="text/javascript">
alert("Record added successfully!");
</script>
<?php
}
?>
<div id="serv">
<b>Enter a new taxi service</b>
<br/><br/>
<form name="servForm" action="<?php $PHP_SELF; ?>" method="post" >
<table width="300" border="0">
<tr>
<td>Name</td>
<td><input type="text" name="name" style="text-align:right" /></td>
</tr>
</table>
</div>
<div id="choseLoc">
<table border="0">
<br>Selecteer afdeling:
<div id="">
<input type="checkbox" name="chk1[]" value="1">1<br>
<input type="checkbox" name="chk1[]" value="2">2<br>
<input type="checkbox" name="chk1[]" value="3">3<br>
<input type="checkbox" name="chk1[]" value="4">4<br>
<input type="checkbox" name="chk1[]" value="5">5<br>
<input type="checkbox" name="chk1[]" value="6">6<br>
<input type="checkbox" name="chk1[]" value="7">7<br>
<input type="checkbox" name="chk1[]" value="8">8
<div/>
<div id="">
<input type="checkbox" name="chk1[]" value="9">9<br>
<input type="checkbox" name="chk1[]" value="10">10<br>
<input type="checkbox" name="chk1[]" value="11">11<br>
<input type="checkbox" name="chk1[]" value="12">12<br>
<input type="checkbox" name="chk1[]" value="13">13<br>
<input type="checkbox" name="chk1[]" value="14">14<br>
<input type="checkbox" name="chk1[]" value="15">15<br>
<input type="checkbox" name="chk1[]" value="16">16<br>
<div/>
<div id="">
<input type="checkbox" name="chk1[]" value="17">17<br>
<input type="checkbox" name="chk1[]" value="18">18<br>
<input type="checkbox" name="chk1[]" value="19">19<br>
<input type="checkbox" name="chk1[]" value="20">20<br>
<input type="checkbox" name="chk1[]" value="21">21<br>
<input type="checkbox" name="chk1[]" value="22">22<br>
<input type="checkbox" name="chk1[]" value="23">23<br>
<input type="checkbox" name="chk1[]" value="24">24
<div/>
<div id="">
<input type="checkbox" name="chk1[]" value="25">25<br>
<input type="checkbox" name="chk1[]" value="26">26<br>
<input type="checkbox" name="chk1[]" value="27">27<br>
<input type="checkbox" name="chk1[]" value="28">28<br>
<input type="checkbox" name="chk1[]" value="29">29<br>
<input type="checkbox" name="chk1[]" value="30">30<br>
<input type="checkbox" name="chk1[]" value="31">31<br>
<input type="checkbox" name="chk1[]" value="32">32
<div/>
</table>
</div>
<br/>
<div id="buttons">
<input type="reset" value="Clear" /> <input type="submit" value="Save" name="savebtn" />
</form>
</div>
</body>
</html>