Jump to content

[SOLVED] urlencode / urldecode failing on MySQL error


colombian

Recommended Posts

I'm trying to figure out why this isn't working...

Here is the encode part, which works fine. (URL gets the added '+')

<a href="seminar_content.php?seminar=<?php echo urlencode($name);?>"><?php echo $name;?></a>

 

However, when I try to decode it:

$seminar = urldecode($_GET['seminar']);
$query = "SELECT * FROM seminar_content WHERE title = {$seminar}";

 

The page errors out on the query with:

---

Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'theft' at line 1

---

Basically, the word right after the first '+' sign.

 

I tried the code above using the rawurlencode and rawurldecode, and got the same results, only that it was the word after the '%20'.

I tried using htmlspecialchars function infront too, without luck.

 

Any help would be greatly appreciated!

 

 

 

try using mysql_escape_string on each value you use in the query,

 

eg:

$seminar = urldecode($_GET['seminar']);
$query = "SELECT * FROM seminar_content WHERE title = ".mysql_escape_string($seminar);

 

Also make sure each value is enclosed in single quotes, eg:

 

$seminar = urldecode($_GET['seminar']);
$query = "SELECT * FROM seminar_content WHERE title = '".mysql_escape_string($seminar)."'";

 

and its also a good idea to enclose fields/tables with backticks, eg:

 

$seminar = urldecode($_GET['seminar']);
$query = "SELECT * FROM `seminar_content` WHERE `title` = '".mysql_escape_string($seminar)."'";

 

 

 

hope this helps,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.