Jump to content

mysql query/fetch problem with $_GET['']


bujashaka

Recommended Posts

Hello!

 

I've been into mysql and encountered a problem, not serious one but it is bugging me.

 

I can do dynamic page linking as follows, in short hand....

 

echo "<a href=\"foo.php?page=" . $vastaus['id'] ."\">" . $vastaus['menu_name'] . "</a><br />";   // URL LINK

 

function showcontent() {   /// FUNCTION TO DISPLAY CONTENT FROM SERVER.
        global $yhteys;
        $sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE id=" . $_GET['page'];
        $kysely= mysql_query($sql, $yhteys);
        $content = mysql_fetch_assoc($kysely) or die(mysql_error());
            
        echo strip_tags($content['content'], "<br><dt><dl>");

Problem is... I can make this work with the ID, how ever, i want the URL bar saying it like this -> index.php?page=Info.

 

This way it looks smarter (tells more to a user) and not just numbers as IDs.

 

If i try to do the query like this...

 

$sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE menu_name=" . $_GET['page'];

It says unknown column "Info, Services". etc etc.

It can only regonize the first column in each row. ( aka the id=number)

I've tryed num_rows, fetch_array and fetch_assoc. I can't find a way to accomplish it.

 

 

PLEASE i know this is simple, need help.

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/281394-mysql-queryfetch-problem-with-_get/
Share on other sites

you have to surround it in quotes if it's text

    $sql .= "WHERE menu_name='" . $_GET['page']."'";

 

Hello!

 

I've been into mysql and encountered a problem, not serious one but it is bugging me.

 

I can do dynamic page linking as follows, in short hand....

 

echo "<a href=\"foo.php?page=" . $vastaus['id'] ."\">" . $vastaus['menu_name'] . "</a><br />";   // URL LINK

 

function showcontent() {   /// FUNCTION TO DISPLAY CONTENT FROM SERVER.
        global $yhteys;
        $sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE id=" . $_GET['page'];
        $kysely= mysql_query($sql, $yhteys);
        $content = mysql_fetch_assoc($kysely) or die(mysql_error());
            
        echo strip_tags($content['content'], "<br><dt><dl>");

 

Problem is... I can make this work with the ID, how ever, i want the URL bar saying it like this -> index.php?page=Info.

 

This way it looks smarter (tells more to a user) and not just numbers as IDs.

 

If i try to do the query like this...

 

$sql = "SELECT * ";
        $sql .= "FROM subjects ";
        $sql .= "WHERE menu_name=" . $_GET['page'];

 

It says unknown column "Info, Services". etc etc.

It can only regonize the first column in each row. ( aka the id=number)

I've tryed num_rows, fetch_array and fetch_assoc. I can't find a way to accomplish it.

 

 

PLEASE i know this is simple, need help.

Thanks in advance!

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.