Hi Pig (doesn't sound like a nice opening lineπ),
I really think I'm just being dumb with this question and I imagine that you're probably cursing the lack of intellegence on my part by now but if I could just pick your brains 1 more time....
I have written out below exactly how the "Add engineer" pages work so that you can get a better idea of where it is I'm going wrong. The resulting problem is at the end.
On Page 1
4 input boxes where the user inputs the engineer username, fullname, password and site..
On Page 2
Error checking to ensure that all info entered didn't already exist and all required fields have been filled in.
PHP code then runs to insert the new engineer into the Database.
$insert_engineer = "INSERT INTO " . engineers. " VALUES ('" . $_POST['username'] . "','','" . $_POST['name'] . "','" . md5($_POST['password']) . "','" . $_POST['site'] . "')";
mysql_query($insert_engineer) OR die(mysql_error());
Now run a query to get the auto allocated engineer number from the engineers table (added to in the last statement) and assign it to the variable
$_SESSION['eng_no'] -
$get_eng_no = "SELECT eng_no FROM " . engineers . " WHERE username='" . $_POST['username'] . "'";
$get_eng_no_result = mysql_query($get_eng_no) OR die(mysql_error());
while( $row = mysql_fetch_array($get_eng_no_result) )
{
$_SESSION['eng_no'] = $row['eng_no'];
}
Now show the user a selection of check boxes with each of the job catagories from the job_cat table.
$job_cat_query = "SELECT * FROM " . job_cat . "";
$job_cat_result = mysql_query($job_cat_query) OR die(mysql_error());
while( $row = mysql_fetch_array($job_cat_result) )
{
echo "<td width='5%'>
<input type='checkbox' name='job_cat[]' value='".$row['job_cat_no']."'>".$row['job_cat']."
</td>
</tr>";
}
echo "</tbody></table>";
On Page 3
Assign a query to insert the new engineer into the eng_job_cat table along with his/her selected job catagories-
$insert_into_eng_job_cat = "INSERT INTO " . eng_job_cat . " VALUES('" . $_SESSION['eng_no'] . "','" . $_POST['job_cat'] . "')";
Now run a while loop to insert the information into the eng_job_cat table as many times as there is supplied information -
while( $row = mysql_fetch_array($_POST['job_cat']) )
{
mysql_query($insert_into_eng_job_cat) OR die(mysql_error());
}
Here I get an error message. Now I understand the meaning of the error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
as the information I'm asking it to execute with didn't come from a MySQL query but my question is what do I need to supply to the while loop to make it run through each of the submitted check boxes? Or do I need something other than a while loop?
Secondly, if a check box isn't selected, does that mean that it is just not added to the array?
I know that job_cat is now an array containing (I hope) the selected check boxes and their corrosponding job catagory values as using print $_POST['job_cat']; in the code prints out the word "Array", its just that I don't know how to extract them.
Thanks for your time on this.