php and wml variable problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Elaine121
    New Member
    • Aug 2007
    • 23

    php and wml variable problem

    Hi. I'm creating a mobile website using wml and php.
    In wml I have a textfield. I can display the value of the field by using variable correct but when I try to use the variable in a mysql select query nothing happens. I know my query is correct it's like the variable is just empty.
    Here is my code:

    Code:
    $sql="SELECT * FROM words WHERE afrikaans='$(word)'"; //$(word) is the variable from the textfield
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    $row = mysql_fetch_array($result);
    echo $row['english'] . " " . $row['afrikaans'];
    Any help would be appreciated
    Thanx
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by Elaine121
    Hi. I'm creating a mobile website using wml and php.
    In wml I have a textfield. I can display the value of the field by using variable correct but when I try to use the variable in a mysql select query nothing happens. I know my query is correct it's like the variable is just empty.
    Here is my code:



    Any help would be appreciated
    Thanx
    $(word) is invalid syntax in PHP. You should be doing $word, or ${word}.

    Comment

    • Elaine121
      New Member
      • Aug 2007
      • 23

      #3
      that still doesnt work. the $(word) is the syntax for wml variable.
      so when I add that to a php variable it displays. but still not in the query.
      Code:
      $word="$(name)";
      echo $word; // Here it displays the value i typed in correctly
      $sql="SELECT * FROM words WHERE afrikaans='$word'";

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by Elaine121
        that still doesnt work. the $(word) is the syntax for wml variable.
        so when I add that to a php variable it displays. but still not in the query.
        Print out $sql and see what the string is.

        Also, I cannot find anywhere that says $(word) is valid syntax in PHP even if it is WML.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          The problem is that PHP is parsed before the WML is. So, when you say $word = "$(name)"; the $word variable contains the actual string "$(word)". However, when you print this to the browser, WML realises it is a WML variable and substitutes it for whatever value it contains.

          When you print $sql, I bet it shows SELECT * FROM words WHERE afrikaans = $(name).

          Comment

          • Elaine121
            New Member
            • Aug 2007
            • 23

            #6
            Thanx for the replies! I figured it out. I just used $_GET to get the value from the textfield. It works perfectly now

            Comment

            Working...