1

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'

3
  • 1
    You're just missing the trailing ) for the VALUES, change the string to "INSERT into images (image_name, url) VALUES ('".$fileName."', 'images/".$fileName."')" Commented Sep 17, 2018 at 4:05
  • You should parameterize your query. Commented Sep 17, 2018 at 4:08
  • You must use PDO for security reasons to prevent injections. Commented Sep 17, 2018 at 5:10

2 Answers 2

1

You can store image value into one variable

 $imgPath = 'images/'.$fileName;

Above variable you can pass into the query

Sign up to request clarification or add additional context in comments.

Comments

0

try this,you are missing one bracket

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

2 Comments

Your closing parenthesis is on the wrong side of the quote.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.