Append variable To string in php insert

Append variable To string in php insert



I'm having an issue appending a file name variable to a string in a sql insert like so


$insert = $mysqlConn->query("INSERT into images (image_name, url) VALUES ('".$fileName."', 'images/".$fileName."'");



I can do it with just the $fileName and it works fine but my syntax is wrong. I'm simply trying to make sure that every file name inserted starts with 'images/'



So if I'm inserting 'red.jpg' it would be 'images/red.jpg'






You're just missing the trailing ) for the VALUES, change the string to "INSERT into images (image_name, url) VALUES ('".$fileName."', 'images/".$fileName."')"

– Nick
Sep 17 '18 at 4:05


)


VALUES


"INSERT into images (image_name, url) VALUES ('".$fileName."', 'images/".$fileName."')"






You should parameterize your query.

– user3783243
Sep 17 '18 at 4:08






You must use PDO for security reasons to prevent injections.

– Krishnadas PC
Sep 17 '18 at 5:10




2 Answers
2



You can store image value into one variable


$imgPath = 'images/'.$fileName;



Above variable you can pass into the query



try this,you are missing one bracket


$insert = ("INSERT into images (image_name, url) VALUES ('".$fileName."', 'images/".$fileName."')");






Your closing parenthesis is on the wrong side of the quote.

– user3783243
Sep 17 '18 at 4:07






Please don't post answers to questions which are just simple typos. Instead, make a comment (as I have already done) and flag the question as "off-topic" due to a typographical error. Questions like this add no value to the site and will eventually be deleted, thus causing you to lose any reputation that you may gain from answering.

– Nick
Sep 17 '18 at 4:09



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế