Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to insert multiple ID's in one linked table?
    primarykey
    data
    text
    <p>I want to insert de EmployeeID and the KnowledgeID in Knowledgedetail. He creates the employee but does nothing in the Knowledgedetail. I'm there now no code, I have tried so many things but i have no idea.<br> As first in Addprofile.php you make the profile and at least you choose yoour knowledge. My question is if a make a profile and choose the knowledge how get i de ID's in knowledgedetail.</p> <p><strong>Table 1<br> Employees</strong>: EmployeeID, Name, Establishment, E-Mail, Phonenumber, Photo, Description<br> <strong>Table 2<br> Knowledge</strong>: KnowledgeID, Knowledge<br> <strong>Table 3<br> Knowledgedetail</strong>: KnowledgedetailID, EmployeeID KnowledgeID </p> <p>EmployeeID out Employees have a relation with EmployeeID out Knowledgedetail and<br> KnowledgeID out Knowledge have a relation with KnowledgeID out Knowledegedetail</p> <p>Addprofile.php</p> <pre><code>&lt;?php include("connection.php"); ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Information System&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="css/test.css"&gt; &lt;meta charset ="utf-8"&gt; &lt;link rel='stylesheet' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/smoothness/jquery-ui.css' type='text/css' media='screen' /&gt; &lt;link rel='stylesheet' href='css/ui.multiselect.css' type='text/css' media='screen' /&gt; &lt;script src="../Informatiesysteem/js/jquery.min.js"&gt;&lt;/script&gt; &lt;script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'&gt;&lt;/script&gt; &lt;script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js'&gt;&lt;/script&gt; &lt;script type='text/javascript' src='../Informatiesysteem/js/ui.multiselect.js'&gt;&lt;/script&gt; &lt;script type='text/javascript'&gt; jQuery(document).ready(function() { jQuery("#selectitems").multiselect(); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt; &lt;div id="logo"&gt;&lt;/div&gt; &lt;div id="header"&gt; &lt;h1&gt;Add Profile&lt;/h1&gt; &lt;/div&gt; &lt;div id="menu"&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;?php $result = mysql_query("select knowledgeid, knowledge from knowledge"); $items = array(); $selected = array(); while ($row = mysql_fetch_array($result)){ $id [] = $row [ 'knowlegdeid' ]; $items[] = $row[ 'knowledge' ]; } //form processing if (isset($_POST['selectitems'])) { $selected = $_POST['selectitems']; } if (!empty($selected)) : print_r($selected); endif; ?&gt; &lt;form enctype="multipart/form-data" id="my form" method="post" action="Addedprofile.php"&gt; Name: &lt;input type="text" name="name" /&gt;&lt;/br&gt; Establishment: &lt;input type="text" name="establishment"/&gt;&lt;/br&gt; E-Mail: &lt;input type="email" name="email"/&gt;&lt;/br&gt; Phonenumber: &lt;input type="tel" name="phonenumber"/&gt;&lt;/br&gt; Photo: &lt;input type="file" name="photo"/&gt;&lt;/br&gt; Description: &lt;textarea rows="4" cols="50" name="description"&gt;&lt;/textarea&gt;&lt;/br&gt; Knowledge: &lt;select name="selectitems[]" id="selectitems" multiple="multiple" style="width: 450px; height: 180px;"&gt; &lt;?php //first we add the list of selected items if any foreach ($selected as $sel) { ?&gt; &lt;option value="&lt;?php echo $sel; ?&gt;" selected="selected"&gt;&lt;?php echo $id[$sel]; $items[$sel];?&gt;&lt;/option&gt; &lt;?php } ?&gt; &lt;?php foreach ($items as $i =&gt; $v) { //then insert all items, skipping those who were added above if (in_array($d, $i, $selected)) : continue; endif; //skip ?&gt; &lt;option value="&lt;?php echo $d, $i; ?&gt;"&gt;&lt;?php echo $v; ?&gt;&lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; &lt;/br&gt;&lt;/br&gt;&lt;/br&gt;&lt;/br&gt; &lt;input type="submit" name="add_profile" value="Add profile" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Addedprofile.php</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;meta http-equiv="refresh" content=";URL=Addprofile.php" /&gt; &lt;/html&gt; &lt;?php include ("connection.php"); $Name = $_POST['name']; $Establishment = $_POST['establishment']; $Email = $_POST['email']; $Phonenumber = $_POST['phonenumber']; $Photo = $_POST['photo']; $Description = $_POST['description']; $sql = "INSERT INTO employees ( name, establishment, email, phonenumber, photo, description ) VALUES ('". $Name ."', '". $Establishment ."', '". $Email ."', '". $Phonenumber ."', '". $Photo ."', '". $Description ."')"; $sqldetail = "INSERT INTO knowledgedetail ( employeeid, knowledgeid ) VALUES ......................."; $add = mysql_query($sql); if ($add === false){ echo 'Profile is not created'; } else { echo "Profile created"; } echo '&lt;/br&gt;'; $knowledge = mysql_query($sqldetail); if ($add === false){ echo 'Knowledge is not added'; } else { echo "Knowledge added"; } echo '&lt;/br&gt;'; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload