Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert into 2 tables at once into mysql databse from arrays
    primarykey
    data
    text
    <p>One called Job and the other is called Attributes. The Attributes table depend on the Job table because One table can have a lot of Attributes. The job table contains several fields, namely </p> <blockquote> <p>Jobid(auto increment, PRIMARY KEY), JobName, Jobdescription</p> </blockquote> <p>The Attributes table contains the following fields</p> <blockquote> <p>id(auto increment, PRIMARY KEY, AttribName, Score, Jobid(Foreign Key from the Job Table).</p> </blockquote> <p>The number of attributes to be entered per job varies, therefore one job can have 10 attributes, while the other job may have 2, 3,4, etc attributes.</p> <p>The following is the code I created before I got stuck.</p> <p>Insert_job.php</p> <pre><code>&lt;?php include 'html/head.php';//connect to connect to the database and initialize all functions include 'scripts/functions/init.php'; include 'html/page_title.php'; include 'html/top_menu.php'; include 'titles/Job_insert.php'; if(empty($_POST)=== false) { $R_fields = array('JobName','JobDesc','JobDuties','RecruitmentProcess','ContractType','SPackage'); foreach($_POST as $key=&gt;$value) { if (empty($value) &amp;&amp; in_array($key,$R_fields)=== true) { $errors[] = 'fields marked with (*) are required'; break 1; } } if(empty($errors)=== true) { if($_POST['DirectorateName'] == '------ select ------') { $errors[] ='Please select Directorate Name'; } if($_POST['Attributes'] == '-select-') { $errors[] ='Please Select the Number of Attributes'; } } } include 'html/job_insert.php'; //Check if the form is not empty then submit details if(empty($_POST) === false &amp;&amp; empty($errors)=== true) { //store input into the session variables $_SESSION['JobName'] = $_POST['JobName']; $_SESSION['JobDesc'] = $_POST['JobDesc']; //Store the number of attributes to get captured $_SESSION['Attributes'] = $_POST['Attributes']; //redirect header('Location: Rank.php'); exit(); } else if(empty($errors) === false) { //output errors if the errors array is not empty echo output($errors); } ?&gt; &lt;/div&gt; &lt;!-- div class entry ends here --&gt; &lt;/div&gt; &lt;!-- div post ends here --&gt; &lt;/div&gt; &lt;!-- div idcontents ends here --&gt; &lt;!-- end #content --&gt; &lt;?php include 'html/top_side.php'; include 'html/side_other.php'; include 'html/side_bottom.php'; include 'html/footer.php'; ?&gt; </code></pre> <p>You will notice that I store all input into session variables and carry it to the next page where I will insert everything at once into the two tables.</p> <p>The following code is for Rank.php</p> <pre><code>&lt;?php include 'scripts/functions/init.php'; include 'html/head.php'; include 'html/page_title.php'; include 'html/top_menu.php'; include 'titles/Rank.php'; //declare the Array to store user input $job_array = array(); //declare the Array to store attributes $attributes = array(); //declare the Array to store attributes scores $scores = array(); //Number of input fields selected by user on Job_insert.php page $Number = $_SESSION['Attributes']; //User Input from Job_insert.php page $JobName = $_SESSION['JobName']; $JobDesc = $_SESSION['JobDesc']; $JobDuties = $_SESSION['JobDuties']; $RProcess = $_SESSION['RecruitmentProcess']; $SPackage = $_SESSION['SPackage']; $DName = $_SESSION['DirectorateName']; //Store user input Job details into an array $job_array = array( 'JobName' =&gt;$JobName, 'JobDesc'=&gt;$JobDesc, 'JobDuties' =&gt;$JobDuties, 'RecruitmentProcess'=&gt;$RProcess, 'SPackage'=&gt;$SPackage, 'DirectorateName'=&gt;$DName); //Check if the form is not empty then submit details if(empty($_POST) === false &amp;&amp; empty($errors)=== true) { //submit job details job_insert($job_array); //Store the current jobid into a variable $jobid = mysql_insert_id(); for($i =0;$i&lt;$Number;$count++) { //This is where I am getting stuck } //redirect header('Location: Rank.php'); exit(); } else if(empty($errors) === false) { //output errors if the errors array is not empty echo output($errors); } </code></pre> <blockquote> <p>//output the forms to the screen include 'html/Rank.php';</p> </blockquote> <p>The following is an example of how I store user input into an array</p> <pre><code>&lt;form action = "" method ="POST" enctype="multipart/form-data"&gt; &lt;fieldset&gt; &lt;?php if($Number == 10) { echo '&lt;table border="0"&gt;'; echo '&lt;th&gt;'.'Attribute'.'&lt;/th&gt;'; echo '&lt;th&gt;'.'Score'.'&lt;/th&gt;'; //Print the first row of the result set echo '&lt;tr&gt;'; //First Form echo '&lt;td&gt;'.'&lt;input type="text" size="35" name="attributes[]"&gt;'.'&lt;/td&gt;'; echo '&lt;td&gt;'.'&lt;select id="select1" name ="Score[]"&gt; &lt;option&gt;-select-&lt;/option&gt; &lt;option&gt;10&lt;/option&gt; &lt;option&gt;9&lt;/option&gt; &lt;option&gt;8&lt;/option&gt; &lt;option&gt;7&lt;/option&gt; &lt;option&gt;6&lt;/option&gt; &lt;option&gt;5&lt;/option&gt; &lt;option&gt;4&lt;/option&gt; &lt;option&gt;3&lt;/option&gt; &lt;option&gt;2&lt;/option&gt; &lt;option&gt;1&lt;/option&gt; &lt;/select&gt;'.'&lt;/td&gt;'; echo '&lt;/tr&gt;'; //Second Form echo '&lt;tr&gt;'; echo '&lt;td&gt;'.'&lt;input type="text" size="35" name="attributes[]"&gt;'.'&lt;/td&gt;'; echo '&lt;td&gt;'.'&lt;select id="select2" name = "score[]""&gt; &lt;option&gt;-select-&lt;/option&gt; &lt;option&gt;10&lt;/option&gt; &lt;option&gt;9&lt;/option&gt; &lt;option&gt;8&lt;/option&gt; &lt;option&gt;7&lt;/option&gt; &lt;option&gt;6&lt;/option&gt; &lt;option&gt;5&lt;/option&gt; &lt;option&gt;4&lt;/option&gt; &lt;option&gt;3&lt;/option&gt; &lt;option&gt;2&lt;/option&gt; &lt;option&gt;1&lt;/option&gt; &lt;/select&gt;'.'&lt;/td&gt;'; echo '&lt;/tr&gt;'; </code></pre> <p>Basically I am storing user input into array called Attributes and another Array Called Score. insertion of the job details into the job table works fine, but now I need to insert information contained in the Attributes and Score array into the mysql database. Please assist</p>
    singulars
    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.
    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