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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:10:36+00:00 2026-05-13T08:10:36+00:00

I am trying to make a simple query to a small MYSQL table, but

  • 0

I am trying to make a simple query to a small MYSQL table, but when I insert the Where clause, I suddenly get an invalid query error (added a while(mysql_fetch_array ){} when working without the where). The MYSQL console gives a 1064 (syntax) error, however, I checked the MYSQL documentation and I am using the proper syntax as far as I can determine.

<?php
$ind=rand(1,3);
$quote=Null;
$sign=Null;
$afil=Null;
$con=mysql_connect(localhost,root,********);//connect to database
mysql_select_db("phone_site",$con);//select table
$query="SELECT * FROM quotes WHERE index=$ind";//get the row for that index
$data=mysql_query($query);
//print out text
print ("<p id=\"quote\">" . $data['quote'] . "</p>");
print ("<p id=\"ename\">" . $data['sign'] . "</p>");
print ("<p id=\"afill\">--  " . $data['afil'] . "</p>");
mysql_close($con);//close connection
?>

Anyone know what the problem is? I’m using XAMPP. Is there something wrong with its MYSQL?

  • 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-13T08:10:37+00:00Added an answer on May 13, 2026 at 8:10 am

    INDEX is one of MySQL’s Reserved Words :

    Certain words such as SELECT, DELETE,
    or BIGINT are reserved and require
    special treatment for use as
    identifiers such as table and column
    names. This may also be true for the
    names of built-in functions.

    Reserved words are permitted as
    identifiers if you quote them as
    described in Section 8.2, “Schema
    Object Names”

    If you have a column with that kind of name, you must quote the column name — see Schema Object Names :

    The identifier quote character is the
    backtick (“`”)

    Which means your query should look like this :

    $query="SELECT * FROM quotes WHERE `index`=$ind";
    

    To complete my answer, after seeing dustmachine’s one, who said :

    I’m a little surprised that it didn’t
    complain when the table was created.

    I suppose the table has been created with some tool like phpMyAdmin or MySQL Workbench ; and those generaly (always, for some) quote column names, to avoid that kind of problem.

    Edit after the comment : I didn’t see, but you are using this kind of code :

    $data=mysql_query($query);
    print ("<p id=\"quote\">" . $data['quote'] . "</p>");
    

    The mysql_query function doesn’t diretly return the data : it only returns a “ressource” (quoting the manual’s page) :

    The returned result resource should be
    passed to mysql_fetch_array(),
    and other functions for dealing with
    result tables, to access the returned
    data.

    Not sure it’ll solve all your problems (nothing being displayed, not even the raw HTML tags is odd), but it might at least help a bit…

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

Sidebar

Related Questions

I'm trying to make a simple mysql_fetch_array but for some reasons I get the
I'm trying to make a simple blackjack program. Sadly, I'm having problems right off
I'm trying to make a simple C# web server that, at this stage, you
Trying to make a MySQL-based application support MS SQL, I ran into the following
I'm trying to make the case for click-once and smart client development but my
I am trying to make a small gridview that lists the results of a
I've a custom module with custom table, now, i'm trying to make something like
I'm trying to make things simpler. Here is my code: If Threading.Monitor.TryEnter(syncRoot) Then Try
Trying to make a make generic select control that I can dynamically add elements
Trying to make a generic PL/SQL procedure to export data in specific XML format,

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.