Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-19-2004, 08:03 PM   #1 (permalink)
rmill9681
Registered User
 
Join Date: Sep 2004
Posts: 8
rmill9681 is on a distinguished road
WML PHP and MySQL

I am trying to access a database through a cell phone. First page you enter a name to search for. This returns results on a second page.

I am able to enter a search name and it returns incorrect results from the database because for some reason the input parameter is not getting passed from the main wml page to the php code.

Here is the first page

Code:
<?php

Header("Content-type: text/vnd.wap.wml");
Header("Cache-Control: no-cache, must-revalidate");
Header("Pragma: no-cache");
echo ("<?xml version='1.0'?>");
?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml" >
<wml>
<card id="search" title="SaintSearch">
<p> 
  <do type="accept">
  <go href="index2.php" method="post">
	<postfield value="$skier"/>

  </go>
  </do>
  Name: <input title="Name" name="skier"/>

</p>
</card>
</wml>

HERE IS THE PHP page

Code:
<?php

Header("Content-type: text/vnd.wap.wml");
printf("<?xml version=\"1.0\"?>\n");
printf("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" "
        ."\"http://www.wapforum.org/DTD/wml_1.1.xml\" >\n");
printf("<wml>\n");

?>
	<wml>
	<card id="index2" title="sql">
	<?php
	@ $db = mysql_pconnect('localhost', 'xxx', 'xxxxx');

	if (!$db)
	{
		echo 'Error: Could not connect to database. Please try again later.';
		exit;
	}

	mysql_select_db('saintData') or die (mysql_error()."<br />Couldn't select database"); 

	$query = "select lastname, firstname from skiers where (firstname like '%$chicken%' or lastname like '%$skier%') AND (is_hidden = '0')";

	$result = mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query"); 
	
    	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        	print $row["lastname"]."<br>\n";
        }


	mysql_free_result($result);
	
	?>
	</card>
	</wml>
rmill9681 is offline   Reply With Quote
Old 11-20-2004, 03:29 AM   #2 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
<--- Has no experience of WML but would like to learn it some day

Can you not pass the variable as a GET variable?
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 11-20-2004, 06:34 AM   #3 (permalink)
rmill9681
Registered User
 
Join Date: Sep 2004
Posts: 8
rmill9681 is on a distinguished road
i tried get, but that didn't work either
rmill9681 is offline   Reply With Quote
Old 11-20-2004, 07:19 AM   #4 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Depending on your PHP installation, using plain $skier in the SQL may not work. Try using $_POST['skier'] or $_REQUEST['skier'] .

Worst case put something at the top of the PHP page to see what the WML page is requesting. eg:

PHP Code:
<pre>
<?php print_r($_POST); ?>
</pre>
At the least you can see if anything is making it through.

-r
idx is offline   Reply With Quote
Old 11-20-2004, 08:18 AM   #5 (permalink)
rmill9681
Registered User
 
Join Date: Sep 2004
Posts: 8
rmill9681 is on a distinguished road
I get: array ( )
rmill9681 is offline   Reply With Quote
Old 11-20-2004, 09:15 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
Quote:
Originally Posted by rmill9681
I get: array ( )
u sure you did print_r() and not print()

if you just get Array() on a print_r(), then the array is empty.
__________________
Mike
sde is offline   Reply With Quote
Old 11-20-2004, 09:19 AM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
i also noticed this line:
Code:
<postfield value="$skier"/>
php is not on when you use that line of code, so $skier will have no php value, you might want to try:
Code:
<postfield value="<?=$skier?>"/>
that is the php shortcut for echoing a value. it would be the equivalent to
Code:
<postfield value="<? echo $skier; ?>"/>
__________________
Mike
sde is offline   Reply With Quote
Old 11-20-2004, 09:38 AM   #8 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
in proper XML don't you need to put a space before the self closing slash, like this?

Code:
<postfield value="<? echo $skier; ?>"/>   <!-- BAD -->
<postfield value="<? echo $skier; ?>" />  <!-- GOOD -->
__________________
Current Project
Redline is offline   Reply With Quote
Old 11-20-2004, 12:33 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
i don't think it really matters about the space.
__________________
Mike
sde is offline   Reply With Quote
Old 11-20-2004, 12:50 PM   #10 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Hmm, alright. I had read this on W3Schools XHTML page

Quote:
http://www.w3schools.com/xhtml/xhtml_html.asp
IMPORTANT Compatibility Note:

To make your XHTML compatible with today's browsers, you should add an extra space before the "/" symbol like this: <br />, and this: <hr />.
But it could be outdated
__________________
Current Project
Redline is offline   Reply With Quote
Old 11-20-2004, 12:59 PM   #11 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
good find. i think the main browsers will not care either way, but he IS on a cell phone browser, so he should definately consider that.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML form preview then INSERT using PHP & MySQL SteveSoler PHP 13 08-27-2008 10:47 PM
Simple PHP MySQL code: confused. easilyi Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 10-24-2004 07:53 PM
cant connect to mysql databases using php eran PHP 11 08-07-2004 08:02 AM
Help with setting up mySQL and PHP Ilya020 PHP 11 03-19-2003 05:10 AM


All times are GMT -8. The time now is 04:35 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting