Hello I want to insert in a table the values selected from a dropdown menu and values from a user that was previosly created . When I do the insert the only values that get inserted into the tables area the ones from the drop down list. But the other values dont get inserted. Please help me. Here is the code.
$query= "INSERT INTO employee (UserName, Password, Name, LastName, " .
"Email, Phone, Classification_ClassificationID) VALUES" .
" ('$user1', SHA('$password1'),'$name', '$lastname', '$email', " .
" '$phone_number', '$classification_id')";
queryMysql($query);
echo '<p>Account Created.</p>';
echo $user1;
}
echo '<h1> Grupo Asignado:</h1>' ;
if (isset ($_POST['submit'])){
foreach ($_POST['toinsert'] as $insert_id) {
$query = "INSERT INTO groupusers (GroupsID, Employee_UserName) Values ('$insert_id', '$user1')" ;
queryMysql($query);
echo mysql_num_rows($result);
echo '<br />';
}
}
开发者_开发百科
$query = "SELECT * FROM employeegroups";
$result = queryMysql($query);
while ($row = mysql_fetch_array($result)) {
echo '<input type="checkbox" value="' .$row['GroupsID'] . '" name="toinsert[]" />';
echo $row['GroupName'];
echo '<br />';
}
echo '<input type="submit" name="submit" value="Insert" />';
echo '</form>';
echo '</body>';
echo '</html>';
?>
queryMysql($query);
echo mysql_num_rows($result);
Where are you setting this $result
? It's not explicity passed back from your queryMysql() function, so either it's unset at this point, or it's a global variable (bad idea).
As well, have you checked that the queries are actually executing? The mysql query functions return boolean FALSE if the query fails. If you're assuming they succeeded and proceed in your code, you'd end up with the symptoms you have.
精彩评论