Page 1 of 1

PHP URL Variable

Posted: Fri Mar 23, 2007 6:02 pm
by RobbieL
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Evening all,

I'm new to PHP, coming from a Coldfusion background, and am currently creating a very small WML application with PHP. It's a very simple application, but there is one part of the PHP code I'm having trouble with. I'm trying to pass a value of a query through to another page using a URL variable, but just can't seem to get it right.

The code for the entire page is as follows:

Code: Select all

<?php header("Content-Type: text/vnd.wap.wml"); echo '<?xml version="1.0"?>'; ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<?php

$Conn = mssql_connect("STUDENT1X","sql0503101","**********") or die("Unable to connect to server");
$Db=mssql_select_db("sql0503101",$Conn);
$result = mssql_query("SELECT TOP 5 title, author, date , blogID FROM blogs ORDER BY date DESC");

?>

<wml>
	
	<card id="index" title="Metanews">
	<p align="center"><b>Newest 5 Blogs</b></p>
	<?php 
	while($RS = mssql_fetch_array($result)) 
	{
	echo '<p><anchor title="Latest News Stories"><go href="readblogs.php?id=$blogID"/>'.$RS['title'].'</anchor></p>';
	echo '<p><small>Author: '.$RS['author'].'</small></p>';
	echo '<p><small>Date: '.$RS['date'].'</small></p>';
	echo '<p>-----</p>';
	} 
	?>

	<p><do type="prev" label="Back"><prev/></do><do type="accept" label="Home"><go href="index.php"/></do></p>
	</card>

</wml>
What I'm unsure about is the "$blogID" in the URL. I have a query earlier on in the page that calls for blogID, for the purpose of the value going into this URL Varialbe. Is that the right syntax for putting the value of "blogID" in the URL?

Any help would be much apprecaited. :)


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Mar 23, 2007 6:15 pm
by nickvd
Two Choices. Change the single quotes into double quotes

Code: Select all

$foo = 'bar';
echo "HI!: $foo"; //HI!: bar
echo 'HI!: $foo'; //HI!: $foo
Or, use concatenation (you're already using it for $RS['title'])

Code: Select all

echo '<p><anchor title="Latest News Stories"><go href="readblogs.php?id=' . $blogID . '"/>' . $RS['title'] . '</anchor></p>';

Posted: Fri Mar 23, 2007 6:21 pm
by RobbieL
Thanks for the speedy reply, much appreciated.

Tried the second the option you offered first, and received the error message "Unknown MIME type 'text/html'."

Any ideas what that means?

Posted: Sat Mar 24, 2007 8:53 pm
by thiscatis
Hey Abertay student,
I would remove your login and pass from the php code if you show it here ;)