PHP URL Variables

Wee

Wee

Associate
Joined
25 Apr 2006
Posts
130
Location
Scotland
I'm new to PHP and sure there is a simple answer for this, but I can't seem to see it. I'm creating a mobile application, and I have a URL Variable made on one page:

Code:
<go href="readblogs.php?id=$blogID"/>

What I'm unsure about is the "$blogID". 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?
 
It didn't seem to like that. Claims that "<" can't be used in the href attribute. If it helps, the URL is already enclosed with a "<?php ?>.
 
Last edited:
Clarkey said:
what does?


oh and while it might be ok leaving it raw like that for a simple id#, a string should probably be urlencoded.

The mobile emulator does. It's called M3Gate.
 
When I try:

Code:
<go href="readblogs.php?id=<?php echo $blogID; ?>"/>

I get the error: "Bad WML syntax. 'Fatal Error. Ln 8, Col 69 A '<' character cannot be used in attribute 'href', except through &lt;'."

When I try $(blogID), it actually gets through to the page were the link containing the URL Varialbe is, but when I click that link I get an error saying: "Bad WML syntax. 'Error. Ln 3, Col 4 Root element different from DOCTYPE'."
 
LazyManc said:
You only need the extra <?php ?> tags if you're in the middle of some HTML.

I don't know how you're outputting to the page but you could try building the whole link as a string in PHP first and then echoing it?

From what I gather, I have the whole like as a string in PHP at the moment:

Code:
<?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>';
	} 
	?>

Would just putting "echo $blogID;" as the variable work?
 
When I try what i originally had produced the error "Bad WML syntax. 'Error. Ln 3, Col 4 Root element different from DOCTYPE'." when you click the link.

Here's the entire code on the page:

Code:
<?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","B1r12-36") 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 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>
 
Last edited:
LazyManc said:
Code:
echo '<p><anchor title="Latest News Stories"><go href="readblogs.php?id=$blogID"/>'.$RS['title'].'</anchor></p>';

Ah thats why, the string needs to be in double-quotes in order to make it evaluate variables, otherwise it'll just be printing $blogID as a litteral.

try

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

Cheers, will give it a shot when my Uni's VPN connection decides to start working again. :)
 
Sadly, that didn't seem to work. It spits out a "Bad WML syntax. 'Error. Ln 9, Col 47 No character data is allowed by content model'."
 
Stayed up to the wee hours of the morning, racking my brains on how to get it working. But alas, no luck.

Really has me stumped.
 
Cheers for the replies guys, much appreciated.

But before I go ahead and try them, I just tried creating a normal URL string variable, and passing that through to see it if worked. And guess what? It didn't.

Here's what I did on the page blogs.php:

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


Then, on the readblogs.php (the page that link leads too), I did:

Code:
<?php $var = $_GET["id"]; ?>


I then tried to display the variable using on that page using:

Code:
<?php echo "$var"; ?>


And as per usual, it throws a "Bad WML syntax. 'Error. Ln 4, Col 4 Root element different from DOCTYPE'" error at me. I'll go ahead and try your suggestions anyway, but I'm starting to think some funky maybe going on somewhere.
 
Back
Top Bottom