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

  • Home
  • SEARCH
  • 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 8912183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:08:15+00:00 2026-06-15T04:08:15+00:00

Please bear with me, I’m new here – and I’m just starting out with

  • 0

Please bear with me, I’m new here – and I’m just starting out with PHP. To be honest, this is my first project, so please be merciful. 🙂

    $row = mysql_fetch_array(mysql_query("SELECT message FROM data WHERE code = '". (int) $code ."'         LIMIT 1"));
    echo $row['message'];

Would this be enough to fetch the message from the database based upon a pre-defined ‘$code’ variable? I have already successfully connected to the database.

This block of code seems to return nothing – just a blank space. 🙁

I would be grateful of any suggestions and help. 🙂

UPDATE:

Code now reads:

    <?php
    error_reporting(E_ALL);
   // Start MySQL Connection
    REMOVED FOR SECURITY
    // Check if code exists
    if(mysql_num_rows(mysql_query("SELECT code FROM data WHERE code = '$code'"))){
    echo 'Hooray, that works!';
    $row = mysql_fetch_array(mysql_query("SELECT message FROM data WHERE code = '". (int) $code     ."' LIMIT 1")) or die(mysql_error());
    echo $row['message'];
    }
    else {
    echo 'That code could not be found. Please try again!';
    }
    mysql_close();
    ?>
  • 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-15T04:08:16+00:00Added an answer on June 15, 2026 at 4:08 am

    It’s best not to chain functions together like this since if the query fails the fetch will also appear to fail and cause an error message that may not actually indicate what the real problem was.

    Also, don’t wrap quotes around integer values in your SQL queries.

    if(! $rs = mysql_query("SELECT message FROM data WHERE code = ". (int) $code ." LIMIT 1") ) {
        die('query failed! ' . mysql_error());
    }
    $row = mysql_fetch_array($rs);
    echo $row['message'];
    

    And the standard “don’t use mysql_* functions because deprecated blah blah blah”…

    If you’re still getting a blank response you might want to check that you’re not getting 0 rows returned. Further testing would also include echoing out the query to see if it’s formed properly, and running it yourself to see if it’s returning the correct data.

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

Sidebar

Related Questions

Please bear with me if this isn't clear, this is my first posting here.
Please bear in mind that I'm totally new to Rails when answering this.My question
Please bear with me on this one. I am first going to describe an
Please bear with me as I've just started using NetBeans for the first time!
Please bear with me as I've been thrown into the middle of this project
I'm a fairly new programmer so please bear with me on this. I am
I'm fairly new to OpenCL so please bear with me. In the first iteration
I'm just learning javascript so please bear with me here. I'm trying to initiate
I am a PHP newb so please bear with me for this rather simplistic
I'm kind of new to this so please bear with me... Let's say I

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.