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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:35:13+00:00 2026-06-01T18:35:13+00:00

I used php code from tutorial and it worked fine. But when I am

  • 0

I used php code from tutorial and it worked fine. But when I am rewriting it to me it gives me null. This code gives me what I want I mean it gives data in JSON format:

$q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'");
while($e=mysql_fetch_assoc($q))
    $output[]=$e;
print(json_encode($output));

But this code even it looks identically doesn’t work it gives null:

$q=mysql_query("SELECT username, firstname, lastname, email, phone1, skype, city, description 
FROM mdl_user WHERE username LIKE'".$_REQUEST['usern']."'");
while($e=mysql_fetch_assoc($q))
    $output[]=$e;
print(json_encode($output));

If I don’t use $_REQUEST[‘usern’] and am getting data in JSON. But I need to use request to search specific data. So where could be the problem. Because I trustfully don’t understand. It looks the same to me.

  • 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-01T18:35:14+00:00Added an answer on June 1, 2026 at 6:35 pm

    To make a pattern with LIKE use a %. Put it around or at any end, beginning or end.

    $username = mysql_real_escape_string($_REQUEST['usern']);
    
    $q=mysql_query("SELECT username, firstname, lastname, email, phone1, skype, city, description 
    FROM mdl_user WHERE username LIKE '$username%'");
                                     ^
                                     |
     // You also missed this space --+
    

    Note your query is wide open to SQL injection. Just think if someone inserts year as '; drop table people; --. Use mysql_real_escape_string to sanitize those field.

    enter image description here

    And it’s better to use explicitly $_POST or $_GET,ths makes sure your data is coming from proper source.

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

Sidebar

Related Questions

The data for the SQL db used in my PHP code comes from an
I got this code below from a tutorial I'm using to learn PHP. I
I've used this code to have a like btn on my site: <iframe src=http://www.facebook.com/plugins/like.php?href=URL_OF_YOUR_WEBSITE&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80&amp
The following code is from a tutorial ( http://net.tutsplus.com/php/creating-a-php5-framework-part-1/ ), not mine. I have
I'm following a php video tutorial (it's not online sorry) from Lynda.com and used
I have used this tutorial from Google to build a web app that finds
I used the following php code to get the file extension of an uploaded
Consider the following php code used for HTML output: echo <div id='logo2'> <a href='if(checkLanguage())
I'm having a problem with some code that used to work in PHP 4.X
I have recently used a PHP pagination tutorial, Pagination - what it is and

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.