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!
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:
Also not that your
UPDATEquery is going to set the value offullto 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 aWHEREclause in your query.