Jump to content


Retrieving a URL from database problem


7 replies to this topic

#1 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 12:45 PM

Ok, here's my scenerio.
I'm editing some more on this site I'm building, and I'm making it so at the end of a tutorial, it has a little 'Need help? Goto this topic' kind of thing.
Normally fine, just enter URL into database, retireve it, and paste it into the href of a hyperlink, right?

Well apparently not.
I've put the following URL into the database, and confirmed via PHPMyAdmin that is is there.
http://talkdev.com/showthread.php?p=57

Now, logically with this line:
Need help on this tutorial? <a href="'.$support_topic.'">Visit the support topic!</a>
Should result in this:
Need help on this tutorial? <a href="http://talkdev.com/showthread.php?p=57">Visit the support topic!</a>

But no. Some reason it does this.
Need help on this tutorial? <a href="<">Visit the support topic!</a>

All I can say is 'WTF'.

Here is how I am retrieving it from the database.

$result = mysql_query("SELECT * FROM `tutorials` WHERE id = '$_GET[tut]' ORDER BY id DESC") or die(mysql_error());
$tutorial = mysql_fetch_array($result);
$support_topic = $tutorial['support'];

Even just using 'echo $support_topic' gives me the '<'.
Using url_encode does nothing but give me '%3C'.

Any ideas what the hell this is all about?

I've done this with URLs before, using this line.
<a href="<?php echo $url.'">'.$url; ?></a>
Same thing, only that one I had to echo the URL also so I simply used the '">' string on there instead of escaping PHP blocks that close together. Exact same thing though, and it works on that other script, but not this one. :love:

Edited by Demonslay, 26 August 2006 - 12:48 PM.


#2 Pooch

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 26 August 2006 - 05:09 PM

Try using double quotes and escaping the special chars. Same problem?

#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 05:30 PM

If that were the case, then this line would work.
echo $support_topic;
But it does the same and echoes a '<'.
I still don't get it at all, there's not a single '<' in the row, and I've double, triple checked that I am retriving from the correct row, that the data is there (it clearly is there when opened in PHPMyAdmin) and everything. :ph34r:

#4 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 26 August 2006 - 05:43 PM

I dont see why your doing this....Why dont you just add an "suppportid" field or similar, pull that and have...

echo '<a href="http://talkdev.com/showthread.php?p=' . $row['supportid'] . '">Support topic</a>';

...? Instead of storing a full url...

#5 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 06:03 PM

Great idea Matt, but that doesn't fix it. :(

Now it results in this.
<a href="http://talkdev.com/showthread.php?p=<">Support topic</a>

I've changed my column type to INT(11) instead of VARCHAR(255), but nothing changes.
I have it in the database as just hte number '57' for example, but it still pulls that out of the database.
I've tried changing the variable to something like, random, just incase it somehow was clashing with a variable with a Google Adsense (hey, when you'r debugging, you have to put anything into consideration!) but same thing happens.
Just echoing the variable by itself gives '<' still.
I'm completely stumped. If it wasn't getting a value from the variable, it would print just ''. I can't understand where it's getting a less than sign, since I didn't serialize the data or hash it any way at all.
Oh well. :(


EDIT-
Horray I fixed it!
Found the problem.
Notice anything wrong with this?
$result = mysql_query("SELECT * FROM `tutorials` WHERE id = '$_GET[tut]' ORDER BY id DESC") or die(mysql_error());
	$tutorial_count = mysql_num_rows($result);
	$tutorial = mysql_fetch_array($result);
	$id = $tutorial['id'];
	$name = $tutorial['name'];
	$description = $tutorial['description'];
	$category = ucwords($tutorial['category']);
	$author = ucwords($tutorial['author']);
	$author_link = strtolower(str_replace(' ', '_', $author));
	$difficulty = ucwords($tutorial['difficulty']);
	$avatar = $tutorial['avatar'];
	$views = $tutorial['views'];
	$tutorial = $tutorial['tutorial'];
	$support = $tutorial['support'];

Haha, I listed it after I turned the array into a variable, then tried to pull a key value from that string. :ph34r:
I just had to simply flop the $support and $tutorial valariables and all is good to go!
Thanks anyways guys. :D

Edited by Demonslay, 26 August 2006 - 06:09 PM.


#6 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 26 August 2006 - 06:07 PM

Well WTH lol.

$result = mysql_query("SELECT `support` FROM `tutorials` WHERE id = $_GET['tut'] ORDER BY id DESC") or die(mysql_error());
$tutorial = mysql_fetch_array($result);
$support_topic = $tutorial['support'];

I guess you could try that, wouldnt make a difference ill put money on that but since i see rc69 is reading this im sure he'll post something insightful lol.

#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 27 August 2006 - 02:28 PM

I was actually going to post something to help with debugging (which nobody seems to know how to do anymore), but i ran out of time. And as he fixed the problem, i don't need to post anything anymore :D

#8 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 27 August 2006 - 06:07 PM

Ya, I was going crazy with debugging on my own there, took me like, an hour to figure out 'oh wow, this is an array then it's a string and I tried to call it as an array again'.

Thanks again for the help, I'm suprised it returned anything though, since there is no 'support' key for the string. It should have given some error or absolutely nothing I would assume. :huh:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users