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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:06:23+00:00 2026-06-12T09:06:23+00:00

Why do some variables need quotes and others don’t? Example when I connect to

  • 0

Why do some variables need quotes and others don’t? Example when I connect to the DB Variables dont need quotes but when I select or insert into a DB I need quotes.

Example:

//variables
    $username="username";
    $password="password";
    $first=$_POST['first'];
    $last=$_POST['last'];

//connect to DB
   mysql_connect(localhost,$username,$password);
   @mysql_select_db($database) or die( "Unable to connect to database");

//values assigned
    $query = "INSERT INTO guestbook VALUES           
    ('','$first','$last','$email','$web','$comment')";
    mysql_query($query);
  • 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-12T09:06:24+00:00Added an answer on June 12, 2026 at 9:06 am

    This is a string literal: "username". It is a value.
    This is a variable: $username. It can hold any value. Think of it as a placeholder.
    This is a variable inside a string literal: "foo $username bar". It creates a new value.

    When creating SQL queries, you simply pass a string to the database, which it will parse according to SQL syntax rules. SQL syntax requires that you put quotes around certain parts. It has nothing to do with PHP variables.

    Further, this is a constant: localhost. You do not have a constant of that name defined, it is actually an error that PHP recovers from by creating the string 'localhost' from it on the fly. It is actually an error though.

    Read about these individual parts of the PHP syntax: http://www.php.net/manual/en/langref.php.


    You only need quotes if you are creating a new string, e.g.: "foo". Variables never need quotes. You may use variables inside a string literal, so its value will get interpolated: "foo $bar baz". But "$foo" is always unnecessary, since it simply creates a new string whose only content is the content of a variable.

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

Sidebar

Related Questions

I need to summarize a data frame by some variables, ignoring the others. This
I have some variables that I need to set once while installing. For example
I have a Singleton to manage some variables I need in various places in
I just need some clarification on variables A normal variable has 2 parts to
I need to set some server specific variables in a rails application that will
Basically I have some variables that I don't want to preinitialize: originalTime = None
I have some variables inside a template and I don't know where I assigned
I'm using make in Windows and I need to manipulate some variables to create
I need a combine some php and html tricks to make a typical select
I created my array in a method and some variables that need to be

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.