PHP MySQL query for insert with Concatenation assignment variable











up vote
0
down vote

favorite












I was facing the problem with php insert multiple image and the only post id to the database.
In database I have image table and post table, when I upload multiple image the image will store in image table with the current post id.



The problem is the insert syntax is wrong, because the




$insertValuesSQL




is from for each with using .= concatenation assignment to upload the image.



The thing is for I was to add addtional post id easy for me to get the image from which post id, so I have to insert with two thing which is $insertValuesSQL and the $last_id from the post id.



Can someone help me to correct the syntax and able to upload the image with the post id? Aprreciate and thank you.



Error at:



 $insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");


PHP full code:



$targetDir = "uploads/";
$allowTypes = array('jpg','png','jpeg','gif');

$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
if(!empty(array_filter($_FILES['submit-image']['name']))){
foreach($_FILES['submit-image']['name'] as $key=>$val){
// File upload path
$fileName = basename($_FILES['submit-image']['name'][$key]);
$targetFilePath = $targetDir . $fileName;

// Check whether file type is valid
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["submit-image"]["tmp_name"][$key], $targetFilePath)){
// Image db insert sql
$insertValuesSQL .= "('".$fileName."'),";
}else{
$errorUpload .= $_FILES['submit-image']['name'][$key].', ';
}
}else{
$errorUploadType .= $_FILES['submit-image']['name'][$key].', ';
}
}

if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
echo "New record created successfully. Last inserted ID is: " . $last_id;
if(!empty($insertValuesSQL)){
$insertValuesSQL = trim($insertValuesSQL,',');
// Insert image file name into database
$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");
if($insert){
$errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
$statusMsg = "Files are uploaded successfully.".$errorMsg;
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

}else{
$statusMsg = 'Please select a file to upload.';
}


Adding one more



if I using the code below :



                $insert = $conn->query("INSERT INTO test (file_name) VALUES $insertValuesSQL");


It successful to upload multiple image but there no post id for the image



Reference from :
https://www.codexworld.com/upload-multiple-images-store-in-database-php-mysql/










share|improve this question
























  • @user3783243 Yes, that one is insert post query, so after succesful insert post, i get the last id for upload the image with the id
    – Tommy Chong
    Nov 17 at 15:19










  • Output the actual query, it looks like its going to be pretty mangled. I think it'd come out as INSERT INTO test (file_name, asd) VALUES ('filename'),,last_id_value which isn't going to work. Use the mysqli error reporting function so you get the actual error. This also is open to SQL injections. I'd recommend doing this with parameterized queries.
    – user3783243
    Nov 17 at 15:22










  • @user3783243 sorry my bad, I was typed wrong test (file_name, asd)
    – Tommy Chong
    Nov 17 at 15:28










  • This is vulnerable to SQL injection. Don’t ignore the advice to use parameterized queries.
    – Ry-
    Nov 17 at 20:16















up vote
0
down vote

favorite












I was facing the problem with php insert multiple image and the only post id to the database.
In database I have image table and post table, when I upload multiple image the image will store in image table with the current post id.



The problem is the insert syntax is wrong, because the




$insertValuesSQL




is from for each with using .= concatenation assignment to upload the image.



The thing is for I was to add addtional post id easy for me to get the image from which post id, so I have to insert with two thing which is $insertValuesSQL and the $last_id from the post id.



Can someone help me to correct the syntax and able to upload the image with the post id? Aprreciate and thank you.



Error at:



 $insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");


PHP full code:



$targetDir = "uploads/";
$allowTypes = array('jpg','png','jpeg','gif');

$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
if(!empty(array_filter($_FILES['submit-image']['name']))){
foreach($_FILES['submit-image']['name'] as $key=>$val){
// File upload path
$fileName = basename($_FILES['submit-image']['name'][$key]);
$targetFilePath = $targetDir . $fileName;

// Check whether file type is valid
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["submit-image"]["tmp_name"][$key], $targetFilePath)){
// Image db insert sql
$insertValuesSQL .= "('".$fileName."'),";
}else{
$errorUpload .= $_FILES['submit-image']['name'][$key].', ';
}
}else{
$errorUploadType .= $_FILES['submit-image']['name'][$key].', ';
}
}

if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
echo "New record created successfully. Last inserted ID is: " . $last_id;
if(!empty($insertValuesSQL)){
$insertValuesSQL = trim($insertValuesSQL,',');
// Insert image file name into database
$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");
if($insert){
$errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
$statusMsg = "Files are uploaded successfully.".$errorMsg;
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

}else{
$statusMsg = 'Please select a file to upload.';
}


Adding one more



if I using the code below :



                $insert = $conn->query("INSERT INTO test (file_name) VALUES $insertValuesSQL");


It successful to upload multiple image but there no post id for the image



Reference from :
https://www.codexworld.com/upload-multiple-images-store-in-database-php-mysql/










share|improve this question
























  • @user3783243 Yes, that one is insert post query, so after succesful insert post, i get the last id for upload the image with the id
    – Tommy Chong
    Nov 17 at 15:19










  • Output the actual query, it looks like its going to be pretty mangled. I think it'd come out as INSERT INTO test (file_name, asd) VALUES ('filename'),,last_id_value which isn't going to work. Use the mysqli error reporting function so you get the actual error. This also is open to SQL injections. I'd recommend doing this with parameterized queries.
    – user3783243
    Nov 17 at 15:22










  • @user3783243 sorry my bad, I was typed wrong test (file_name, asd)
    – Tommy Chong
    Nov 17 at 15:28










  • This is vulnerable to SQL injection. Don’t ignore the advice to use parameterized queries.
    – Ry-
    Nov 17 at 20:16













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I was facing the problem with php insert multiple image and the only post id to the database.
In database I have image table and post table, when I upload multiple image the image will store in image table with the current post id.



The problem is the insert syntax is wrong, because the




$insertValuesSQL




is from for each with using .= concatenation assignment to upload the image.



The thing is for I was to add addtional post id easy for me to get the image from which post id, so I have to insert with two thing which is $insertValuesSQL and the $last_id from the post id.



Can someone help me to correct the syntax and able to upload the image with the post id? Aprreciate and thank you.



Error at:



 $insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");


PHP full code:



$targetDir = "uploads/";
$allowTypes = array('jpg','png','jpeg','gif');

$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
if(!empty(array_filter($_FILES['submit-image']['name']))){
foreach($_FILES['submit-image']['name'] as $key=>$val){
// File upload path
$fileName = basename($_FILES['submit-image']['name'][$key]);
$targetFilePath = $targetDir . $fileName;

// Check whether file type is valid
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["submit-image"]["tmp_name"][$key], $targetFilePath)){
// Image db insert sql
$insertValuesSQL .= "('".$fileName."'),";
}else{
$errorUpload .= $_FILES['submit-image']['name'][$key].', ';
}
}else{
$errorUploadType .= $_FILES['submit-image']['name'][$key].', ';
}
}

if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
echo "New record created successfully. Last inserted ID is: " . $last_id;
if(!empty($insertValuesSQL)){
$insertValuesSQL = trim($insertValuesSQL,',');
// Insert image file name into database
$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");
if($insert){
$errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
$statusMsg = "Files are uploaded successfully.".$errorMsg;
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

}else{
$statusMsg = 'Please select a file to upload.';
}


Adding one more



if I using the code below :



                $insert = $conn->query("INSERT INTO test (file_name) VALUES $insertValuesSQL");


It successful to upload multiple image but there no post id for the image



Reference from :
https://www.codexworld.com/upload-multiple-images-store-in-database-php-mysql/










share|improve this question















I was facing the problem with php insert multiple image and the only post id to the database.
In database I have image table and post table, when I upload multiple image the image will store in image table with the current post id.



The problem is the insert syntax is wrong, because the




$insertValuesSQL




is from for each with using .= concatenation assignment to upload the image.



The thing is for I was to add addtional post id easy for me to get the image from which post id, so I have to insert with two thing which is $insertValuesSQL and the $last_id from the post id.



Can someone help me to correct the syntax and able to upload the image with the post id? Aprreciate and thank you.



Error at:



 $insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");


PHP full code:



$targetDir = "uploads/";
$allowTypes = array('jpg','png','jpeg','gif');

$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
if(!empty(array_filter($_FILES['submit-image']['name']))){
foreach($_FILES['submit-image']['name'] as $key=>$val){
// File upload path
$fileName = basename($_FILES['submit-image']['name'][$key]);
$targetFilePath = $targetDir . $fileName;

// Check whether file type is valid
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["submit-image"]["tmp_name"][$key], $targetFilePath)){
// Image db insert sql
$insertValuesSQL .= "('".$fileName."'),";
}else{
$errorUpload .= $_FILES['submit-image']['name'][$key].', ';
}
}else{
$errorUploadType .= $_FILES['submit-image']['name'][$key].', ';
}
}

if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
echo "New record created successfully. Last inserted ID is: " . $last_id;
if(!empty($insertValuesSQL)){
$insertValuesSQL = trim($insertValuesSQL,',');
// Insert image file name into database
$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL,$last_id");
if($insert){
$errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
$statusMsg = "Files are uploaded successfully.".$errorMsg;
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

}else{
$statusMsg = 'Please select a file to upload.';
}


Adding one more



if I using the code below :



                $insert = $conn->query("INSERT INTO test (file_name) VALUES $insertValuesSQL");


It successful to upload multiple image but there no post id for the image



Reference from :
https://www.codexworld.com/upload-multiple-images-store-in-database-php-mysql/







php mysql sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 at 15:26

























asked Nov 17 at 15:14









Tommy Chong

1469




1469












  • @user3783243 Yes, that one is insert post query, so after succesful insert post, i get the last id for upload the image with the id
    – Tommy Chong
    Nov 17 at 15:19










  • Output the actual query, it looks like its going to be pretty mangled. I think it'd come out as INSERT INTO test (file_name, asd) VALUES ('filename'),,last_id_value which isn't going to work. Use the mysqli error reporting function so you get the actual error. This also is open to SQL injections. I'd recommend doing this with parameterized queries.
    – user3783243
    Nov 17 at 15:22










  • @user3783243 sorry my bad, I was typed wrong test (file_name, asd)
    – Tommy Chong
    Nov 17 at 15:28










  • This is vulnerable to SQL injection. Don’t ignore the advice to use parameterized queries.
    – Ry-
    Nov 17 at 20:16


















  • @user3783243 Yes, that one is insert post query, so after succesful insert post, i get the last id for upload the image with the id
    – Tommy Chong
    Nov 17 at 15:19










  • Output the actual query, it looks like its going to be pretty mangled. I think it'd come out as INSERT INTO test (file_name, asd) VALUES ('filename'),,last_id_value which isn't going to work. Use the mysqli error reporting function so you get the actual error. This also is open to SQL injections. I'd recommend doing this with parameterized queries.
    – user3783243
    Nov 17 at 15:22










  • @user3783243 sorry my bad, I was typed wrong test (file_name, asd)
    – Tommy Chong
    Nov 17 at 15:28










  • This is vulnerable to SQL injection. Don’t ignore the advice to use parameterized queries.
    – Ry-
    Nov 17 at 20:16
















@user3783243 Yes, that one is insert post query, so after succesful insert post, i get the last id for upload the image with the id
– Tommy Chong
Nov 17 at 15:19




@user3783243 Yes, that one is insert post query, so after succesful insert post, i get the last id for upload the image with the id
– Tommy Chong
Nov 17 at 15:19












Output the actual query, it looks like its going to be pretty mangled. I think it'd come out as INSERT INTO test (file_name, asd) VALUES ('filename'),,last_id_value which isn't going to work. Use the mysqli error reporting function so you get the actual error. This also is open to SQL injections. I'd recommend doing this with parameterized queries.
– user3783243
Nov 17 at 15:22




Output the actual query, it looks like its going to be pretty mangled. I think it'd come out as INSERT INTO test (file_name, asd) VALUES ('filename'),,last_id_value which isn't going to work. Use the mysqli error reporting function so you get the actual error. This also is open to SQL injections. I'd recommend doing this with parameterized queries.
– user3783243
Nov 17 at 15:22












@user3783243 sorry my bad, I was typed wrong test (file_name, asd)
– Tommy Chong
Nov 17 at 15:28




@user3783243 sorry my bad, I was typed wrong test (file_name, asd)
– Tommy Chong
Nov 17 at 15:28












This is vulnerable to SQL injection. Don’t ignore the advice to use parameterized queries.
– Ry-
Nov 17 at 20:16




This is vulnerable to SQL injection. Don’t ignore the advice to use parameterized queries.
– Ry-
Nov 17 at 20:16












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You need to put the $last_id into every list of values being inserted, not as a separate parameter. But you can't do this because you're creating $insertValuesSQL before you set $last_id.



You can move the loop that creates $insertValuesSQL to after you set $last_id, but another way is to use MySQL's built-in function LAST_INSERT_ID():



$insertValuesSQL .= "('".$fileName."', LAST_INSERT_ID()),";


Then you can take $last_id out of the later INSERT query:



$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL");





share|improve this answer





















  • LAST_INSERT_ID() can create race condition though, can't it?
    – user3783243
    Nov 17 at 15:46






  • 1




    No, it's exactly the same as mysqli_insert_id(). They both get the last ID inserted by the current connection.
    – Barmar
    Nov 17 at 15:49










  • Thanks I solve with you solution, appreciate :D
    – Tommy Chong
    Nov 17 at 15:54











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53352527%2fphp-mysql-query-for-insert-with-concatenation-assignment-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










You need to put the $last_id into every list of values being inserted, not as a separate parameter. But you can't do this because you're creating $insertValuesSQL before you set $last_id.



You can move the loop that creates $insertValuesSQL to after you set $last_id, but another way is to use MySQL's built-in function LAST_INSERT_ID():



$insertValuesSQL .= "('".$fileName."', LAST_INSERT_ID()),";


Then you can take $last_id out of the later INSERT query:



$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL");





share|improve this answer





















  • LAST_INSERT_ID() can create race condition though, can't it?
    – user3783243
    Nov 17 at 15:46






  • 1




    No, it's exactly the same as mysqli_insert_id(). They both get the last ID inserted by the current connection.
    – Barmar
    Nov 17 at 15:49










  • Thanks I solve with you solution, appreciate :D
    – Tommy Chong
    Nov 17 at 15:54















up vote
2
down vote



accepted










You need to put the $last_id into every list of values being inserted, not as a separate parameter. But you can't do this because you're creating $insertValuesSQL before you set $last_id.



You can move the loop that creates $insertValuesSQL to after you set $last_id, but another way is to use MySQL's built-in function LAST_INSERT_ID():



$insertValuesSQL .= "('".$fileName."', LAST_INSERT_ID()),";


Then you can take $last_id out of the later INSERT query:



$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL");





share|improve this answer





















  • LAST_INSERT_ID() can create race condition though, can't it?
    – user3783243
    Nov 17 at 15:46






  • 1




    No, it's exactly the same as mysqli_insert_id(). They both get the last ID inserted by the current connection.
    – Barmar
    Nov 17 at 15:49










  • Thanks I solve with you solution, appreciate :D
    – Tommy Chong
    Nov 17 at 15:54













up vote
2
down vote



accepted







up vote
2
down vote



accepted






You need to put the $last_id into every list of values being inserted, not as a separate parameter. But you can't do this because you're creating $insertValuesSQL before you set $last_id.



You can move the loop that creates $insertValuesSQL to after you set $last_id, but another way is to use MySQL's built-in function LAST_INSERT_ID():



$insertValuesSQL .= "('".$fileName."', LAST_INSERT_ID()),";


Then you can take $last_id out of the later INSERT query:



$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL");





share|improve this answer












You need to put the $last_id into every list of values being inserted, not as a separate parameter. But you can't do this because you're creating $insertValuesSQL before you set $last_id.



You can move the loop that creates $insertValuesSQL to after you set $last_id, but another way is to use MySQL's built-in function LAST_INSERT_ID():



$insertValuesSQL .= "('".$fileName."', LAST_INSERT_ID()),";


Then you can take $last_id out of the later INSERT query:



$insert = $conn->query("INSERT INTO test (file_name, post_id) VALUES $insertValuesSQL");






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 at 15:44









Barmar

413k34238339




413k34238339












  • LAST_INSERT_ID() can create race condition though, can't it?
    – user3783243
    Nov 17 at 15:46






  • 1




    No, it's exactly the same as mysqli_insert_id(). They both get the last ID inserted by the current connection.
    – Barmar
    Nov 17 at 15:49










  • Thanks I solve with you solution, appreciate :D
    – Tommy Chong
    Nov 17 at 15:54


















  • LAST_INSERT_ID() can create race condition though, can't it?
    – user3783243
    Nov 17 at 15:46






  • 1




    No, it's exactly the same as mysqli_insert_id(). They both get the last ID inserted by the current connection.
    – Barmar
    Nov 17 at 15:49










  • Thanks I solve with you solution, appreciate :D
    – Tommy Chong
    Nov 17 at 15:54
















LAST_INSERT_ID() can create race condition though, can't it?
– user3783243
Nov 17 at 15:46




LAST_INSERT_ID() can create race condition though, can't it?
– user3783243
Nov 17 at 15:46




1




1




No, it's exactly the same as mysqli_insert_id(). They both get the last ID inserted by the current connection.
– Barmar
Nov 17 at 15:49




No, it's exactly the same as mysqli_insert_id(). They both get the last ID inserted by the current connection.
– Barmar
Nov 17 at 15:49












Thanks I solve with you solution, appreciate :D
– Tommy Chong
Nov 17 at 15:54




Thanks I solve with you solution, appreciate :D
– Tommy Chong
Nov 17 at 15:54


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53352527%2fphp-mysql-query-for-insert-with-concatenation-assignment-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]