Connecting Tech Pros Worldwide Help | Site Map

php and wml variable problem

Newbie
 
Join Date: Aug 2007
Posts: 23
#1: 3 Weeks Ago
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:

Expand|Select|Wrap|Line Numbers
  1. $sql="SELECT * FROM words WHERE afrikaans='$(word)'"; //$(word) is the variable from the textfield
  2. $result=mysql_query($sql);
  3. $count=mysql_num_rows($result);
  4. $row = mysql_fetch_array($result);
  5. echo $row['english'] . " " . $row['afrikaans'];
Any help would be appreciated
Thanx
best answer - posted by Markus
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).
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: 3 Weeks Ago

re: php and wml variable problem


Quote:

Originally Posted by Elaine121 View Post

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}.
Newbie
 
Join Date: Aug 2007
Posts: 23
#3: 3 Weeks Ago

re: php and wml variable problem


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.
Expand|Select|Wrap|Line Numbers
  1. $word="$(name)";
  2. echo $word; // Here it displays the value i typed in correctly
  3. $sql="SELECT * FROM words WHERE afrikaans='$word'";
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: 3 Weeks Ago

re: php and wml variable problem


Quote:

Originally Posted by Elaine121 View Post

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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#5: 3 Weeks Ago

re: php and wml variable problem


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).
Newbie
 
Join Date: Aug 2007
Posts: 23
#6: 3 Weeks Ago

re: php and wml variable problem


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