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 7770847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:30:27+00:00 2026-06-01T16:30:27+00:00

I have this code – which is trying to get variables from the URL

  • 0

I have this code – which is trying to get variables from the URL and then do a MYSQL select based on the criteria (except the NULL values). However, I believe I am going somewhere but I don’t know where:

<?php

    include('db.php'); // include your code to connect to DB.
    $tbl_name="mobile"; //your table name

    $model = ($_GET['model'] ? $_GET['model'] : NULL);
    $mins = ($_GET['mins']  ? $_GET['mins']  : NULL);    
    $texts = ($_GET['texts'] ? $_GET['texts'] : NULL); 
    $freegift = ($_GET['free-gift'] ? $_GET['free-gift'] : NULL);
    $network = ($_GET['network']   ? $_GET['network']   : NULL);
    $plan = ($_GET['plan']  ? $_GET['plan']  : NULL);
    $vars = array($model, $mins, $texts, $freegift, $network, $plan);


    foreach($vars as $value) {
        $value = (isset($_GET[$value]) ? $_GET[$value] : NULL);
        unset ($vars[$value]);  //sweeping the NULL ones 
    }
    $where_clause = $vars[0]; //the only remaining value after previous cleanup


    $where = '';
    if (count($whereClauses) > 0) {
        $where = ' WHERE '.implode(' AND ',$whereClauses);
    }
    $sql5 = mysql_query("SELECT * FROM $tbl_name".$where);

This doesn’t work at all. It should work like www.domain.com/page.php?mobile=Samsung&mins=500 – the vars should be used to perform the search.

  • 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-06-01T16:30:28+00:00Added an answer on June 1, 2026 at 4:30 pm

    I think I understand what you want. But your code has too many errors (both semantic and security). Therefore, I suggest the following code:

    include 'db.php';
    $tbl_name = 'mobile';
    
    $default_list = array('model', 'mins', 'texts', 'free-gift', 'network', 'plan');
    $ins_vars = array_intersect_key($_GET, array_flip($default_list));
    
    if(!empty($ins_vars))
    {
       foreach($ins_vars as $key => $val)
       {
          $val = mysql_real_escape_string($val);
          $ins_vars[$key] = "{$key}='{$val}'";
       }
    
       $where_clause = implode(' AND ', $ins_vars);
       $sql5 = mysql_query("SELECT * FROM {$tbl_name} WHERE {$where_clause}");
    }
    

    ps. Not tested but should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which export data from GridView to csv. It works with
I have this code: $('.couch-hide').click(function() { $(this).animate({right:0},1000, 'easeOutBounce'); }); I am trying to get
I have this code which gets info from an other class but I have
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);
I have this code, which works fine, but I would like to be able
I have this code to send variables to a datagrid on another page protected
I have this code: IList<Foo1> ou = session.CreateQuery(from Foo1 as f1 JOIN FETCH f1.foo2
I have this code: <label for=subject accesskey=S>Subject</label> <select name=subject type=text id=subject> <option value=a dog>Dog</option>
I have this code that I have written in Ruby, but when trying to
I have this code which getting html code of page and than replace all

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.