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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:46:05+00:00 2026-06-14T22:46:05+00:00

I have a small PHP Application which is supposed to allow a user to

  • 0

I have a small PHP Application which is supposed to allow a user to enter a 4 digit year into an XHTML web form and return all the information saved in the MySQL database with a lower year than the one provided. The years are stored in the db under the column yearPublished. I have the query working and I get no errors, however no data is being returned.

Here is the SQL file for creating the database:

CREATE TABLE IF NOT EXISTS `books` (
`ISBN` char(13) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`title` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`author_firstName` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`author_lastName` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`genre` varchar(35) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`publisher` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`yearPublished` varchar(4) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`price` float DEFAULT '0.0',
PRIMARY KEY (`ISBN`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

And here is the PHP code that executes the query:

    if(isset($_POST['submitForm'])) {
    $strBookPubYear = $_POST['pubYear'];

    if(empty($strBookPubYear)) {
        print("<p class='error'>You must enter a 4 digit publication date!</p>\n");
    } else {
        if(!is_numeric($strBookPubYear)) {
            print("<p class='error'>The publication date must be numeric.</p>\n");
        } else {
            if(!(strlen($strBookPubYear) === 4)) {
                print("<p class='error'>The Publication date must be exactly 4 characters long.</p>\n ");
            } else {

        $sqlQuery = mysql_query("SELECT yearPublished FROM books WHERE yearPublished < '$strBookPubYear'");

        if($sqlQuery === false) {
            print("<p class='error'>Could not execute the query, please try again.</p>\n");
        } else {

notice the $sqlQuery variable that is supposed to get all the data where the yearPublished is lower than $strBookPubYear. I have read multiple tutorials on this, but they all are using the MySQL ‘Date’ data-type. In my case I am using a text data-type. Please do not tell me to use mysqli, this specific project does not require me to use mysqli.

  • 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-14T22:46:06+00:00Added an answer on June 14, 2026 at 10:46 pm

    Your yearPublished is stored as a varchar, which is essentially a string. Therefore, when you say yearPublished < '$strBookPubYear', it probably is not doing what you think that it is doing. Store yearPublished as an INTEGER. Either way it takes 4 bytes.

    You can manually cast the varchar to a number in the query, and it should probably start working.

    SELECT yearPublished FROM books WHERE (yearPublished+0) < '$strBookPubYear'
    

    OK, that wasn’t really the problem! Try this error checking block, to spit out some better clues:

    // Check result
    // This shows the actual query sent to MySQL, and the error. Useful for debugging.
    if (!$sqlQuery) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        die($message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application in PHP in which when a button ( type='button'
I have a small application written in PHP and a mysql database hosted on
I have a small php file which just creates the tables in a database.
Hii , I have a small php form. I need it to come in
I have a small script which im using to test PHP mail(), as below:
I have a small contact form: <form method=post action=contact.php name=contactform id=contactform> <fieldset> <legend>Please fill
I'm working on yet another framework for PHP, and have run into a small
We have a web application which has been developed over the past 7 months.
I am currently building a small web application for publishing stories using PHP and
I am working on a very small PHP and MySQL application. I have a

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.