0

I'm trying to concat $_SESSION["username"] with $q. I've tried several ways but can't seem to concat the two.

Attempts

VALUES ('".$_SESSION["username"] + $q."', '".$_SESSION["username"]."', '$q')
VALUES ('".$_SESSION["username"]." + $q', '".$_SESSION["username"]."', '$q')
VALUES ('".$_SESSION["username"]. + $q"', '".$_SESSION["username"]."', '$q')

I've looked up string operators but I think the syntax is slightly different with the $_SESSION[] variable. http://php.net/manual/en/language.operators.string.php

1 Answer 1

1

Use the dot operator to concatenate strings in PHP:

VALUES ('" .$_SESSION["username"] . $q . "', '" .$_SESSION["username"]. "', '$q')

Note that your code is subject to SQL injection.

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

1 Comment

It wasn't working but I realized there has to be a period on the right side of $q too. Thanks!

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.