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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:48:48+00:00 2026-06-15T13:48:48+00:00

I am trying to run an update that assigns a varchar a huge block

  • 0

I am trying to run an update that assigns a varchar a huge block of data based on multiple variables. Here is a sample my sql code:

   'update details set full = "Miles reported by $name - $empname - $deptname\n\n"
 "Total Miles in $month: $dailytotal\n"
 "Total Business Miles in $month: $busitotal\n"
 "Total Personal Miles in $month: $perstotal\n\n"
  "$month 1: START: $start1...STOP: $stop1...DAILY: $daily1...BUSINESS: $busi1...PERSONAL: $personal1\n"
  "$month 2: START: $start2...STOP: $stop2...DAILY: $daily2...BUSINESS: $busi2...PERSONAL: $personal2\n"
  ')
    or die "Could not prepare sql statement";

that works fine and all but the problem is its storing the variables as ‘$name’ and not what $name is equal to along with all of the other variables. How can i fix this and sorry about my formatting. thanks in advance!

  • 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-15T13:48:49+00:00Added an answer on June 15, 2026 at 1:48 pm

    You are using single quotes around your string, so the variables and other escape sequences are not going to be interpreted the way you are hoping. See the PHP documentation here:

    http://php.net/manual/en/language.types.string.php

    Also in your case, you should be placing single quotes around the entire field that you are to be inserting. For ease of reading the code, and to get the line returns the way you want, I would HIGHLY recommend setting your string value in a variable and using that variable in your query like this:

    $insert_string = "Miles reported by $name - $empname - $deptname\n\n".
    "Total Miles in $month: $dailytotal\n".
    "Total Business Miles in $month: $busitotal\n".
    "Total Personal Miles in $month: $perstotal\n\n".
    "$month 1: START: $start1...STOP: $stop1...DAILY: $daily1...BUSINESS: $busi1...PERSONAL: $personal1\n".
    "$month 2: START: $start2...STOP: $stop2...DAILY: $daily2...BUSINESS: $busi2...PERSONAL: $personal2\n";
    $query = "UPDATE details SET full = '$insert_string'";
    

    Also not that your UPDATE query is going to set the value of full to this string for every record in the table. I don’t know if this is intended or not (I am guessing it is not since this seems to be a month-specific record). If you only want to update a single record or subset of records, you need a WHERE clause in your query.

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

Sidebar

Related Questions

I'm trying to run an update query that updates one table based on rows
I'm using SQL Server 2000 and i'm trying to run an update query to
Here is some Transact-SQL I am trying to run via sqlcmd (SQL Server 2005).
I'm trying to run a very quick update query to record that a user's
I'm trying to update a single record in a table, but when I run
Using T-SQL, I would like to execute an UPDATE statement that will SET columns
I have been trying to run rake but it seems that ever since I
I'm trying to run a simple query with node-mysql like this: client.query(UPDATE mytable SET
I'm trying to run db:migrate. This fails however because one of the tables that
Good day! I'm trying to run the same update statement with the same params

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.