Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6334765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:43:22+00:00 2026-05-24T18:43:22+00:00

I somewhat have a weird problem. I’m trying to check if a certain value

  • 0

I somewhat have a weird problem. I’m trying to check if a certain value exists in a database via a self created function, like this

function is_in_db($val,$row,$db){
    $query = mysql_query("SELECT ".$row." FROM ".$db." WHERE ".$row." = '".$val."'");

    if(mysql_num_rows($query)){
        return true;
    }else{
        return false;
    }
}

As far as i know this works (i checked it outside the function and echo’d the results. It works fine there. But when i do this, it keps constantly displaying ‘yes’ (where it should display ‘no’)

    if(is_in_db($_aGET,"c_link","fe_content")){
        echo("yes");
    }else{
        echo("no");
    }

All the variables work and are correctly, i checked that!

Does anybody know what i do wrong here?


Edit:
Here is some additional information. My database looks (simplified) like this:

Database: fe_content
+--------+--------+
| c_link | c_page |
+--------+--------+
|  one   | page 1 |
|  two   | page 2 |
| three  | page 3 |
+-----------------+

I have the following url www.domain.com/page/two

In page.php i have the following (relevant only) code:

if(!empty($_SERVER['PATH_INFO'])){
    $_aGET = substr($_SERVER['PATH_INFO'], 1);
    $_aGET = explode('/', $_aGET);
}

function is_in_table ($val, $col, $table) {
    return (mysql_num_rows(mysql_query("SELECT `$col` FROM `$table` WHERE `$col` = '$val' LIMIT 1")) > 0);
}

if(empty($_aGET[0])){
    echo("Were on page.php");
}else{
    if(is_in_table($_aGET,"c_link","fe_content")){
        echo("yes");
    }else{
        echo("no");
    }
}

And this somehow won’t work..


SOLVED!

Aahh!!!

I now see that i used $_aGET in stead of $_aGET[0] Ahh!

Sorry and thanks for helping all!!!!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:43:23+00:00Added an answer on May 24, 2026 at 6:43 pm

    It’s a bit difficult to answer your question without knowing more about your db and your variables, but I’ll give it a go.

    // A made up table called 'users'
    +-------+---------+
    | id    | name    |
    +-------+---------+
    | 1     | Bob     |
    +-------+---------+
    | 2     | John    |
    +-------+---------+
    
    // And here's your function
    function rowExists($value, $field, $table){
        $sanitized = is_numeric($value) ? $value : "'" . $value . "'";
        $query = mysql_query("SELECT " . $field . " FROM " . $table . " WHERE " . $field . " = " . $sanitized);
    
        // Credit: @Omeid Herat
        return (boolean) mysql_num_rows($query);
    }
    
    // Some usage examples
    rowExists('Bob', 'name', 'users'); // true
    rowExists('Dave', 'name', 'users'); // false
    

    This should work, but it is definitely not safe from SQL injections.

    Updated

    $page = explode('/', $_SERVER['REQUEST_URI']);
    
    if(empty($page[1])){
        echo "Were on page.php";
    }else{
        if(is_in_table($page[1], "c_link", "fe_content")){
            echo "yes";
        }else{
            echo "no";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have somewhat simple problem with my Flash projects. I've installed Flash CS5, created
I have a somewhat weird requirement to be able to listen to a number
I have somewhat of a problem. We have a centralized interface engine that will
I have a somewhat complex custom user control, created in C# .NET, which is
I have a somewhat complex plot task in matplotlib that requires--I think--an autoscale() function
Connecting to another computer via sockets (which I have somewhat succeeded at, yay me)
I have somewhat interesting development situation. The client and deployment server are inside a
Does VS2008 have somewhat C++0x standard support? DUPLICATE Visual Studio support for new C
I have a somewhat messily-formatted Objective-C code base. Is there a way to have
I have a somewhat complicated branching structure at work (at least for me). It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.