0

I am sending information to a php file through a AJAX post mat hod and the PHP can echo the data but will not assign it to a variable and I can not seem to understand why. The first echo works but the second echo only seems to get the hours. The AJAX in not encoded.

I just learned PHP a few weeks ago so I expect this problem to be very simple to fix.

Thank you

<?php
    echo ($_POST['userName']);
    $usernam = ($_POST['userName']);
    $eventid = ($_POST['eventid']);
    $hours = ($_POST["hours"]);
    echo $eventid+$usernam+$hours+"<br><br><br>";
?>
6
  • 1
    You don't need parentheses around those variables. Commented Mar 11, 2014 at 1:39
  • Variable and string Concatenation in php is . not + Commented Mar 11, 2014 at 1:40
  • @Popnoodles is there a rule as to when use quotes? Commented Mar 11, 2014 at 6:30
  • 1
    Quotes? Strings inside double-quotes " are parsed, strings inside single quotes ' are not. So echo "$a"; gives the value of a, the same as echo $a; but echo '$a'; gives the literal string $a not its value. Parentheses ( ) like in math are used to force precedence (isolate a calculation/condition), e.g. ($a - $b) * $c may not equal $a - $b * $c and if (($a || $b) && $c) may not equal if ($a || $b && $c) Commented Mar 11, 2014 at 12:30
  • 1
    Yes you need them. You're producing "Use of undefined constant" notices without them. Pick one type (single or double) and stick with it, otherwise you'll end up searching for both variations, should you need to find something. Commented Mar 12, 2014 at 16:14

1 Answer 1

3

concatenate with .

echo $eventid.$usernam.$hours."<br><br><br>";

I've done this countless times when going back and forth with php and javascript

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

Comments

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.