Hi all:

Trying to concatenate a variable inside an UPDATE statement without success.

    

$iplayer_4 = 'Zap';
$iuserID_4 = $_COOKIE['WishList'];
$iuserID_4 = str_replace("UserID=","", $iuserID_4);
$params_4 = array($iplayer_4);

$sql_4 = "UPDATE WList SET WishCount=WishCount+1, UserId = $iuserID_4 . ', ' . UserID WHERE Player = ?";

$stmt_4 = sqlsrv_query($conn, $sql_4, $params_4);

sqlsrv_free_stmt($stmt_4);
sqlsrv_close($conn);

When I remove "UserId = $iuserID_4 . ', ' . UserID" the UPDATE works. With it is in it doesn't update.

Thank you!

    You used single quotes to start the string, so you must use single quotes to end the string as well, yet you're using single quotes.

      bradgrafelman;10975355 wrote:

      You used single quotes to start the string, so you must use single quotes to end the string as well, yet you're using single quotes.

      I'm sorry but I don't see what you are referring to. The UPDATE statement has double quotes beginning and end. I am using single quotes around the comma to concatenate.

        Do you understand what 'concatenation' even means in terms of the PHP language? In a nutshell, it is the joining two separate pieces of strings together to form a single string. Example:

        $string = "Hello " . "world" . "!";

        Your code, however, has a single string with periods in it.

          I am attempting to concatenate

          $iuserID_4 . ', ' . UserID

          I want to to one string in the database record

          So if

          $iuserID_4= 123abc
          and
          UserID = 678oiu

          I want the record to be

          123abc, 678oiu

            Write a Reply...