PDO Insert with Select Statement Error / Invalid parameter number [duplicate]












1
















This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • My PDO Statement doesn't work

    1 answer




Doing the query manually in PHPMyAdmin



INSERT INTO productimages (ImageURL, productID)
VALUES('http://test.jpg', (SELECT id
FROM products
WHERE products.MPN = 'test'));


Works just fine.



But trying to use PDO...



try {
$sql = "INSERT INTO productimages (ImageURL, productID)
VALUES(':image_url', (SELECT id
FROM products
WHERE products.MPN = ':mpn'));";
$data = [
'image_url' => $image_url,
'mpn' => $mpn
];
$stmt = $conn->prepare($sql);
$stmt->execute($data);
}
catch(PDOException $e)
{
echo '<h2 style="color:red;">' . $e->getMessage() . '</h2>';
}


I am always getting this error:




SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens




How do I properly form this INSERT query to perform with PDO?










share|improve this question













marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 22:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    @FunkFortyNiner Thank you. That worked. Once I added backtick's (`) to the tables and columns, it performs correctly.

    – Brian Bruman
    Nov 18 '18 at 23:01








  • 1





    You're welcome Brian; always glad to see that the duplicate(s) helped in solving it yourself, cheers :)

    – Funk Forty Niner
    Nov 18 '18 at 23:02
















1
















This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • My PDO Statement doesn't work

    1 answer




Doing the query manually in PHPMyAdmin



INSERT INTO productimages (ImageURL, productID)
VALUES('http://test.jpg', (SELECT id
FROM products
WHERE products.MPN = 'test'));


Works just fine.



But trying to use PDO...



try {
$sql = "INSERT INTO productimages (ImageURL, productID)
VALUES(':image_url', (SELECT id
FROM products
WHERE products.MPN = ':mpn'));";
$data = [
'image_url' => $image_url,
'mpn' => $mpn
];
$stmt = $conn->prepare($sql);
$stmt->execute($data);
}
catch(PDOException $e)
{
echo '<h2 style="color:red;">' . $e->getMessage() . '</h2>';
}


I am always getting this error:




SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens




How do I properly form this INSERT query to perform with PDO?










share|improve this question













marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 22:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    @FunkFortyNiner Thank you. That worked. Once I added backtick's (`) to the tables and columns, it performs correctly.

    – Brian Bruman
    Nov 18 '18 at 23:01








  • 1





    You're welcome Brian; always glad to see that the duplicate(s) helped in solving it yourself, cheers :)

    – Funk Forty Niner
    Nov 18 '18 at 23:02














1












1








1









This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • My PDO Statement doesn't work

    1 answer




Doing the query manually in PHPMyAdmin



INSERT INTO productimages (ImageURL, productID)
VALUES('http://test.jpg', (SELECT id
FROM products
WHERE products.MPN = 'test'));


Works just fine.



But trying to use PDO...



try {
$sql = "INSERT INTO productimages (ImageURL, productID)
VALUES(':image_url', (SELECT id
FROM products
WHERE products.MPN = ':mpn'));";
$data = [
'image_url' => $image_url,
'mpn' => $mpn
];
$stmt = $conn->prepare($sql);
$stmt->execute($data);
}
catch(PDOException $e)
{
echo '<h2 style="color:red;">' . $e->getMessage() . '</h2>';
}


I am always getting this error:




SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens




How do I properly form this INSERT query to perform with PDO?










share|improve this question















This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • My PDO Statement doesn't work

    1 answer




Doing the query manually in PHPMyAdmin



INSERT INTO productimages (ImageURL, productID)
VALUES('http://test.jpg', (SELECT id
FROM products
WHERE products.MPN = 'test'));


Works just fine.



But trying to use PDO...



try {
$sql = "INSERT INTO productimages (ImageURL, productID)
VALUES(':image_url', (SELECT id
FROM products
WHERE products.MPN = ':mpn'));";
$data = [
'image_url' => $image_url,
'mpn' => $mpn
];
$stmt = $conn->prepare($sql);
$stmt->execute($data);
}
catch(PDOException $e)
{
echo '<h2 style="color:red;">' . $e->getMessage() . '</h2>';
}


I am always getting this error:




SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens




How do I properly form this INSERT query to perform with PDO?





This question already has an answer here:




  • When to use single quotes, double quotes, and back ticks in MySQL

    12 answers



  • My PDO Statement doesn't work

    1 answer








php mysql pdo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 22:58









Brian BrumanBrian Bruman

34427




34427




marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 22:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 22:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    @FunkFortyNiner Thank you. That worked. Once I added backtick's (`) to the tables and columns, it performs correctly.

    – Brian Bruman
    Nov 18 '18 at 23:01








  • 1





    You're welcome Brian; always glad to see that the duplicate(s) helped in solving it yourself, cheers :)

    – Funk Forty Niner
    Nov 18 '18 at 23:02














  • 1





    @FunkFortyNiner Thank you. That worked. Once I added backtick's (`) to the tables and columns, it performs correctly.

    – Brian Bruman
    Nov 18 '18 at 23:01








  • 1





    You're welcome Brian; always glad to see that the duplicate(s) helped in solving it yourself, cheers :)

    – Funk Forty Niner
    Nov 18 '18 at 23:02








1




1





@FunkFortyNiner Thank you. That worked. Once I added backtick's (`) to the tables and columns, it performs correctly.

– Brian Bruman
Nov 18 '18 at 23:01







@FunkFortyNiner Thank you. That worked. Once I added backtick's (`) to the tables and columns, it performs correctly.

– Brian Bruman
Nov 18 '18 at 23:01






1




1





You're welcome Brian; always glad to see that the duplicate(s) helped in solving it yourself, cheers :)

– Funk Forty Niner
Nov 18 '18 at 23:02





You're welcome Brian; always glad to see that the duplicate(s) helped in solving it yourself, cheers :)

– Funk Forty Niner
Nov 18 '18 at 23:02












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?