I have two tables, Table A and Table B. Table A has 10k records. Table B has those 10K old records and additional records. I need to update the old 10k records in Table B.
I used,
UPDATE CONTENT_WORKFLOW_MASTER CWM, CWSCOPY TMP SET
CWM.PROGRAM_ID = TMP.PROGRAM_ID,
CWM.PROGRAM_TYPE_ID = TMP.PROGRAM_TYPE_ID,
CWM.PROGRAM_TYPE_NAME = TMP.PROGRAM_TYPE_NAME,
CWM.ORIGINAL_TITLE = TMP.ORIGINAL_TITLE,
CWM.SOURCE_GROUP_ID = TMP.SOURCE_GROUP_ID,
CWM.MASTER_TITLE = TMP.MASTER_TITLE,
CWM.PROGRAM_LANGUAGE = TMP.PROGRAM_LANGUAGE,
CWM.REGION = TMP.REGION,
CWM.CW_STATUS = 'NEW',
CWM.COPY_CULTURE = TMP.COPY_CULTURE,
CWM.GENRES = TMP.GENRES,
CWM.AIR_DATE_TIME = TMP.AIR_DATE_TIME,
CWM.PROCESS_ID = TMP.GUID,
CWM.PRIORITY = 0,
CWM.UPDATED_BY_SCHEDULE = 1,
CWM.MODIFIED_USER = 'StoredProcUser',
CWM.MODIFIED_DATE = NOW() WHERE CWM.PROGRAM_ID = TMP.PROGRAM_ID ;
And i used,
UPDATE CONTENT_WORKFLOW_MASTER CWM INNER JOIN t.temp TMP
USING (PROGRAM_ID)
SET
CWM.PROGRAM_ID = TMP.PROGRAM_ID,
CWM.PROGRAM_TYPE_ID = TMP.PROGRAM_TYPE_ID,
CWM.PROGRAM_TYPE_NAME = TMP.PROGRAM_TYPE_NAME,
CWM.ORIGINAL_TITLE = TMP.ORIGINAL_TITLE,
CWM.SOURCE_GROUP_ID = TMP.SOURCE_GROUP_ID,
CWM.MASTER_TITLE = TMP.MASTER_TITLE,
CWM.PROGRAM_LANGUAGE = TMP.PROGRAM_LANGUAGE,
CWM.REGION = TMP.REGION,
CWM.CW_STATUS = 'NEW',
CWM.COPY_CULTURE = TMP.COPY_CULTURE,
CWM.GENRES = TMP.GENRES,
CWM.AIR_DATE_TIME = TMP.AIR_DATE_TIME,
CWM.PROCESS_ID = TMP.GUID,
CWM.PRIORITY = 0,
CWM.UPDATED_BY_SCHEDULE = 1,
CWM.MODIFIED_USER = 'StoredProcUser',
CWM.MODIFIED_DATE = NOW() WHERE CWM.USER_LOCKED=0;
create TEMPORARY table t.temp AS
SELECT DISTINCT CWS.CONTENT_WORKFLOW_STAGING_ID,CWS.PROGRAM_ID,CWS.SOURCE_GROUP_NAME,CWS.COPY_CULTURE,
CWS.PROGRAM_TYPE_ID, CWS.PROGRAM_TYPE_NAME, CWS.ORIGINAL_TITLE, CWS.SOURCE_GROUP_ID, CWS.MASTER_TITLE,
CWS.PROGRAM_LANGUAGE, CWS.REGION, CWS.GENRES, CWS.AIR_DATE_TIME, CWS.GUID,CWS.IS_PROCESSED, CWS.INTERNAL_TRANSACTION_ID
FROM CONTENT_WORKFLOW_STAGING CWS INNER JOIN CONTENT_WORKFLOW_MASTER CWM ON
CWM.PROGRAM_ID = CWS.PROGRAM_ID AND
CWM.SOURCE_GROUP_NAME = CWS.SOURCE_GROUP_NAME AND CWM.COPY_CULTURE = CWS.COPY_CULTURE AND CWM.USER_LOCKED = 0
AND
CWS.IS_PROCESSED = 0 AND CWS.INTERNAL_TRANSACTION_ID = INTERNAL_TRANSACTION_ID;
Both the queries are not full efficient. CAn anyone suggest the efficient way to to that. Within atleast 10 sec.
do you find any issue in these below MySQL query. Actually this Insert query is not working. the tools picks the values from FORM controls correctly but it is not updating.
the values ain't update in MySQL DB. the coding brings the form values correctly but it is not updating in MySQL DB
actually the query where i am using in VB.Net (VS2010)
Private Sub btnupdate_Click(sender As System.Object, e As System.EventArgs) Handles btnupdate.Click
Dim ch_date As Date = dtpdate.Value
If ch_date = getToday(Now) Then
checkdate(ch_date)
Else
checkdate(ch_date)
End If
cleanfields()
End Sub
Function checkdate(ByVal chdate As Date)
Dim tmpreader As MySqlDataReader
Dim usr As String
'Dim dtp_date As Date = dtpdate.Value
usr = getUserName()
usr = getFullName(getUserName())
Try
If main_form.mySQLconn1.State = ConnectionState.Closed Then
main_form.mySQLconn1.Open()
End If
main_form.cmdproductivity.CommandText = "SELECT * FROM productivity WHERE productivity_date = #productivity_date"
main_form.cmdproductivity.Parameters("#productivity_date").Value = chdate
tmpreader = main_form.cmdproductivity.ExecuteReader()
If tmpreader.HasRows Then
main_form.cmdproductivity.CommandText = "UPDATE productivity SET agent = #agent, productivity_date = #productivity_date, actual_date = #actual_date, total_count = #total_count, eq_pr = #eq_pr, c_rebook=#c_rebook, c_nonwatson=#c_nonwatson, c_coa=#c_coa, c_watson=#c_watson, c_velocity=#c_velocity, c_quote=#c_quote, c_crd=#c_crd, c_eclaims=#c_eclaims, c_ecalls=#c_ecalls, c_xi=#c_xi, c_brazil=#c_brazil, c_cancel=#c_cancel, c_queries=#c_queries, c_partrebook=#c_partrebook, c_nci=#c_nci, c_phil=#c_phil, c_qc=#c_qc, c_watsonqc=#c_watsonqc, c_monitor=#c_monitor, c_enduser=#c_enduser, c_idoc=#c_idoc, c_servercancel=#c_servercancel, eq_rebook=#eq_rebook, eq_nonwatson=#eq_nonwatson, eq_coa=#eq_coa, eq_watson=#eq_watson, eq_velocity=#eq_velocity, eq_quote=#eq_quote, eq_crd=#eq_crd, eq_eclaims=#eq_eclaims, eq_ecalls=#eq_ecalls, eq_xi=#eq_xi, eq_brazil=#eq_brazil, eq_cancel=#eq_cancel, eq_queries=#eq_queries, eq_partrebook=#eq_partrebook, eq_nci=#eq_nci, eq_phil=#eq_phil, eq_qc=#eq_qc, eq_watsonqc=#eq_watsonqc, eq_monitor=#eq_monitor, eq_enduser=#eq_enduser, eq_idoc=#eq_idoc, eq_servercancel=#eq_servercancel WHERE productivity_date = #productivity_date"
main_form.cmdproductivity.Parameters("#agent").Value = Trim(usr)
main_form.cmdproductivity.Parameters("#productivity_date").Value = Trim(chdate)
main_form.cmdproductivity.Parameters("#actual_date").Value = getToday(Now)
main_form.cmdproductivity.Parameters("#total_count").Value = Trim(txtcount.Text)
main_form.cmdproductivity.Parameters("#eq_pr").Value = Trim(txtEQPRs.Text)
main_form.cmdproductivity.Parameters("#c_rebook").Value = Trim(txtrebook.Text)
main_form.cmdproductivity.Parameters("#c_nonwatson").Value = Trim(txtnonwatson.Text)
main_form.cmdproductivity.Parameters("#c_coa").Value = Trim(txtcoa.Text)
main_form.cmdproductivity.Parameters("#c_watson").Value = Trim(txtwatson.Text)
main_form.cmdproductivity.Parameters("#c_velocity").Value = Trim(txtvelocity.Text)
main_form.cmdproductivity.Parameters("#c_quote").Value = Trim(txtquote.Text)
main_form.cmdproductivity.Parameters("#c_crd").Value = Trim(txtcrd.Text)
main_form.cmdproductivity.Parameters("#c_eclaims").Value = Trim(txteclaims.Text)
main_form.cmdproductivity.Parameters("#c_ecalls").Value = Trim(txtecalls.Text)
main_form.cmdproductivity.Parameters("#c_xi").Value = Trim(txtxi.Text)
main_form.cmdproductivity.Parameters("#c_brazil").Value = Trim(txtbrazil.Text)
main_form.cmdproductivity.Parameters("#c_cancel").Value = Trim(txtcancel.Text)
main_form.cmdproductivity.Parameters("#c_queries").Value = Trim(txtqueries.Text)
main_form.cmdproductivity.Parameters("#c_partrebook").Value = Trim(txtpartrebook.Text)
main_form.cmdproductivity.Parameters("#c_nci").Value = Trim(txtnci.Text)
main_form.cmdproductivity.Parameters("#c_phil").Value = Trim(txtphil.Text)
main_form.cmdproductivity.Parameters("#c_qc").Value = Trim(txtqc.Text)
main_form.cmdproductivity.Parameters("#c_watsonqc").Value = Trim(txtwatsonqc.Text)
main_form.cmdproductivity.Parameters("#c_monitor").Value = Trim(txtmonitor.Text)
main_form.cmdproductivity.Parameters("#c_enduser").Value = Trim(txtenduser.Text)
main_form.cmdproductivity.Parameters("#c_idoc").Value = Trim(txtidoc.Text)
main_form.cmdproductivity.Parameters("#c_servercancel").Value = Trim(txtservercancel.Text)
main_form.cmdproductivity.Parameters("#eq_rebook").Value = Trim(txtEQrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nonwatson").Value = Trim(txtEQnonwatson.Text)
main_form.cmdproductivity.Parameters("#eq_coa").Value = Trim(txtEQcoa.Text)
main_form.cmdproductivity.Parameters("#eq_watson").Value = Trim(txtEQwatson.Text)
main_form.cmdproductivity.Parameters("#eq_velocity").Value = Trim(txtEQvelocity.Text)
main_form.cmdproductivity.Parameters("#eq_quote").Value = Trim(txtEQquote.Text)
main_form.cmdproductivity.Parameters("#eq_crd").Value = Trim(txtEQcrd.Text)
main_form.cmdproductivity.Parameters("#eq_eclaims").Value = Trim(txtEQeclaims.Text)
main_form.cmdproductivity.Parameters("#eq_ecalls").Value = Trim(txtEQecalls.Text)
main_form.cmdproductivity.Parameters("#eq_xi").Value = Trim(txtEQxi.Text)
main_form.cmdproductivity.Parameters("#eq_brazil").Value = Trim(txtEQbrazil.Text)
main_form.cmdproductivity.Parameters("#eq_cancel").Value = Trim(txtEQcancel.Text)
main_form.cmdproductivity.Parameters("#eq_queries").Value = Trim(txtEQqueries.Text)
main_form.cmdproductivity.Parameters("#eq_partrebook").Value = Trim(txtEQpartrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nci").Value = Trim(txtEQnci.Text)
main_form.cmdproductivity.Parameters("#eq_phil").Value = Trim(txtEQphil.Text)
main_form.cmdproductivity.Parameters("#eq_qc").Value = Trim(txtEQqc.Text)
main_form.cmdproductivity.Parameters("#eq_watsonqc").Value = Trim(txtEQwatsonqc.Text)
main_form.cmdproductivity.Parameters("#eq_monitor").Value = Trim(txtEQmonitor.Text)
main_form.cmdproductivity.Parameters("#eq_enduser").Value = Trim(txtEQenduser.Text)
main_form.cmdproductivity.Parameters("#eq_idoc").Value = Trim(txtEQidoc.Text)
main_form.cmdproductivity.Parameters("#eq_servercancel").Value = Trim(txtEQservercancel.Text)
Else
'main_form.cmdproductivity.CommandText = "INSERT INTO productivity " _
' & "(agent,productivity_date,actual_date,total_count,eq_pr,c_rebook,c_nonwatson,c_coa,c_watson,c_velocity,c_quote,c_crd,c_eclaims,c_ecalls,c_xi,c_brazil,c_cancel,c_queries,c_partrebook,c_nci,c_phil,c_qc,c_watsonqc,c_monitor,c_enduser,c_idoc,c_servercancel,eq_rebook,eq_nonwatson,eq_coa,eq_watson,eq_velocity,eq_quote,eq_crd,eq_eclaims,eq_ecallseq_xi,eq_brazil,eq_cancel,eq_queries,eq_partrebook,eq_nci,eq_phil,eq_qc,eq_watsonqc,eq_monitor,eq_enduser,eq_idoc,eq_servercancel VALUES" _
' & "(#agent,#productivity_date,#actual_date,#total_count,#eq_pr,#c_rebook,#c_nonwatson,#c_coa,#c_watson,#c_velocity,#c_quote,#c_crd,#c_eclaims,#c_ecalls,#c_xi,#c_brazil,#c_cancel,#c_queries,#c_partrebook,#c_nci,#c_phil,#c_qc,#c_watsonqc,#c_monitor,#c_enduser,#c_idoc,#c_servercancel,#eq_rebook,#eq_nonwatson,#eq_coa,#eq_watson,#eq_velocity,#eq_quote,#eq_crd,#eq_eclaims,#eq_ecalls,#eq_xi,#eq_brazil,#eq_cancel,#eq_queries,#eq_partrebook,#eq_nci,#eq_phil,#eq_qc,#eq_watsonqc,#eq_monitor,#eq_enduser,#eq_idoc,#eq_servercancel)"
main_form.cmdproductivity.CommandText = "INSERT INTO productivity(agent, productivity_date, actual_date, total_count, eq_pr, c_rebook, c_nonwatson, c_coa, c_watson, c_velocity, c_quote, c_crd, c_eclaims, c_ecalls, c_xi, c_brazil, c_cancel, c_queries, c_partrebook, c_nci, c_phil, c_qc, c_watsonqc, c_monitor, c_enduser, c_idoc, c_servercancel, eq_rebook, eq_nonwatson, eq_coa, eq_watson, eq_velocity, eq_quote, eq_crd, eq_eclaims, eq_ecalls, eq_xi, eq_brazil, eq_cancel, eq_queries, eq_partrebook, eq_nci, eq_phil, eq_qc, eq_watsonqc, eq_monitor, eq_enduser, eq_idoc, eq_servercancel) VALUES (#agent,#productivity_date,#actual_date,#total_count,#eq_pr,#c_rebook,#c_nonwatson,#c_coa,#c_watson,#c_velocity,#c_quote,#c_crd,#c_eclaims,#c_ecalls,#c_xi,#c_brazil,#c_cancel,#c_queries,#c_partrebook,#c_nci,#c_phil,#c_qc,#c_watsonqc,#c_monitor,#c_enduser,#c_idoc,#c_servercancel,#eq_rebook,#eq_nonwatson,#eq_coa,#eq_watson,#eq_velocity,#eq_quote,#eq_crd,#eq_eclaims,#eq_ecalls,#eq_xi,#eq_brazil,#eq_cancel,#eq_queries,#eq_partrebook,#eq_nci,#eq_phil,#eq_qc,#eq_watsonqc,#eq_monitor,#eq_enduser,#eq_idoc,#eq_servercancel)"
main_form.cmdproductivity.Parameters("#agent").Value = Trim(usr)
main_form.cmdproductivity.Parameters("#productivity_date").Value = Trim(chdate)
main_form.cmdproductivity.Parameters("#actual_date").Value = getToday(Now)
main_form.cmdproductivity.Parameters("#total_count").Value = Trim(txtcount.Text)
main_form.cmdproductivity.Parameters("#eq_pr").Value = Trim(txtEQPRs.Text)
main_form.cmdproductivity.Parameters("#c_rebook").Value = Trim(txtrebook.Text)
main_form.cmdproductivity.Parameters("#c_nonwatson").Value = Trim(txtnonwatson.Text)
main_form.cmdproductivity.Parameters("#c_coa").Value = Trim(txtcoa.Text)
main_form.cmdproductivity.Parameters("#c_watson").Value = Trim(txtwatson.Text)
main_form.cmdproductivity.Parameters("#c_velocity").Value = Trim(txtvelocity.Text)
main_form.cmdproductivity.Parameters("#c_quote").Value = Trim(txtquote.Text)
main_form.cmdproductivity.Parameters("#c_crd").Value = Trim(txtcrd.Text)
main_form.cmdproductivity.Parameters("#c_eclaims").Value = Trim(txteclaims.Text)
main_form.cmdproductivity.Parameters("#c_ecalls").Value = Trim(txtecalls.Text)
main_form.cmdproductivity.Parameters("#c_xi").Value = Trim(txtxi.Text)
main_form.cmdproductivity.Parameters("#c_brazil").Value = Trim(txtbrazil.Text)
main_form.cmdproductivity.Parameters("#c_cancel").Value = Trim(txtcancel.Text)
main_form.cmdproductivity.Parameters("#c_queries").Value = Trim(txtqueries.Text)
main_form.cmdproductivity.Parameters("#c_partrebook").Value = Trim(txtpartrebook.Text)
main_form.cmdproductivity.Parameters("#c_nci").Value = Trim(txtnci.Text)
main_form.cmdproductivity.Parameters("#c_phil").Value = Trim(txtphil.Text)
main_form.cmdproductivity.Parameters("#c_qc").Value = Trim(txtqc.Text)
main_form.cmdproductivity.Parameters("#c_watsonqc").Value = Trim(txtwatsonqc.Text)
main_form.cmdproductivity.Parameters("#c_monitor").Value = Trim(txtmonitor.Text)
main_form.cmdproductivity.Parameters("#c_enduser").Value = Trim(txtenduser.Text)
main_form.cmdproductivity.Parameters("#c_idoc").Value = Trim(txtidoc.Text)
main_form.cmdproductivity.Parameters("#c_servercancel").Value = Trim(txtservercancel.Text)
main_form.cmdproductivity.Parameters("#eq_rebook").Value = Trim(txtEQrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nonwatson").Value = Trim(txtEQnonwatson.Text)
main_form.cmdproductivity.Parameters("#eq_coa").Value = Trim(txtEQcoa.Text)
main_form.cmdproductivity.Parameters("#eq_watson").Value = Trim(txtEQwatson.Text)
main_form.cmdproductivity.Parameters("#eq_velocity").Value = Trim(txtEQvelocity.Text)
main_form.cmdproductivity.Parameters("#eq_quote").Value = Trim(txtEQquote.Text)
main_form.cmdproductivity.Parameters("#eq_crd").Value = Trim(txtEQcrd.Text)
main_form.cmdproductivity.Parameters("#eq_eclaims").Value = Trim(txtEQeclaims.Text)
main_form.cmdproductivity.Parameters("#eq_ecalls").Value = Trim(txtEQecalls.Text)
main_form.cmdproductivity.Parameters("#eq_xi").Value = Trim(txtEQxi.Text)
main_form.cmdproductivity.Parameters("#eq_brazil").Value = Trim(txtEQbrazil.Text)
main_form.cmdproductivity.Parameters("#eq_cancel").Value = Trim(txtEQcancel.Text)
main_form.cmdproductivity.Parameters("#eq_queries").Value = Trim(txtEQqueries.Text)
main_form.cmdproductivity.Parameters("#eq_partrebook").Value = Trim(txtEQpartrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nci").Value = Trim(txtEQnci.Text)
main_form.cmdproductivity.Parameters("#eq_phil").Value = Trim(txtEQphil.Text)
main_form.cmdproductivity.Parameters("#eq_qc").Value = Trim(txtEQqc.Text)
main_form.cmdproductivity.Parameters("#eq_watsonqc").Value = Trim(txtEQwatsonqc.Text)
main_form.cmdproductivity.Parameters("#eq_monitor").Value = Trim(txtEQmonitor.Text)
main_form.cmdproductivity.Parameters("#eq_enduser").Value = Trim(txtEQenduser.Text)
main_form.cmdproductivity.Parameters("#eq_idoc").Value = Trim(txtEQidoc.Text)
main_form.cmdproductivity.Parameters("#eq_servercancel").Value = Trim(txtEQservercancel.Text)
End If
Catch ex As Exception
MsgBox("Database Error: " & ex.ToString() & vbCrLf & "The error have been logged .... ", MsgBoxStyle.OkOnly, main_form.dbErrTitle)
writeLogs("Database Error: " & ex.ToString())
Finally
main_form.mySQLconn1.Close()
End Try
Return True
End Function
I don't calculate your column number, but do you miss one column at end? where is the last id which exists in column but not in VALUSE part:
(eq_servercancel, id) vs
(#eq_servercancel)
It would really help if you edit your answer with the error you are getting, but at a glance:
You are adding "id" to you column list in the INSERT statement, but you do not have a "id" value in your VALUES statement. So either remove "id" from the INSERT statement or send through a value for "id".
so my problem is this, I have a 3 part form that is a service ticket, the 1st part of the form is filled out by the dispatcher and submitted to mysql, the technician then see's they have a ticket assigned to them via email and they pull up the search result for tickets assigned to them and they click on a link in the search result that displays the 2nd form for them to enter what they did and what material and labor there is, this 2nd part of the form is my issue it has multiple values that are similar such as item_qty1, item_qty2, item_qty3 and so on. When I use more than 1 value like item_qty1 in my UPDATE tickets SET query I get a syntax error. Also, I am well aware that my code is subject to sql injection and I will deal with that when I have a working form. So here is my code:
<?php
// database connection //
include 'db_connect.php';
include 'data/var/variables.php';
//Writes the information to the database
mysql_query("UPDATE tickets SET work_performed = $work_performed,
item_qty1 = $item_qty1,
item_qty2 = $item_qty2,
item_qty3 = $item_qty3,
item_qty4 = $item_qty4,
item_qty5 = $item_qty5,
manuf_1 = $manuf_1,
manuf_2 = $manuf_2,
manuf_3 = $manuf_3,
manuf_4 = $manuf_4,
manuf_5 = $manuf_5,
part_number1 = $part_number1,
part_number2 = $part_number2,
part_number3 = $part_number3,
part_number4 = $part_number4,
part_number5 = $part_number5,
part_description1 = $part_description1,
part_description2 = $part_description2,
part_description3 = $part_description3,
part_description4 = $part_description4,
part_description5 = $part_description5,
part_price1 = $part_price1,
part_price2 = $part_price2,
part_price3 = $part_price3,
part_price4 = $part_price4,
part_price5 = $part_price5,
price_extension1 = $price_extension1,
price_extension2 = $price_extension2,
price_extension3 = $price_extension3,
price_extension4 = $price_extension4,
price_extension5 = $price_extension5,
material_total = $material_total,
sales_tax = $sales_tax,
shipping_cost = $shipping_cost,
work_date1 = $work_date1,
work_date2 = $work_date2,
work_date3 = $work_date3,
work_date4 = $work_date4,
work_date5 = $work_date5,
tech_name1 = $tech_name1,
tech_name2 = $tech_name2,
tech_name3 = $tech_name3,
tech_name4 = $tech_name4,
tech_name5 = $tech_name5,
cost_code1 = $cost_code1,
cost_code2 = $cost_code2,
cost_code3 = $cost_code3,
cost_code4 = $cost_code4,
cost_code5 = $cost_code5,
pay_rate1 = $pay_rate1,
pay_rate2 = $pay_rate2,
pay_rate3 = $pay_rate3,
pay_rate4 = $pay_rate4,
pay_rate5 = $pay_rate5,
total_hours1 = $total_hours1,
total_hours2 = $total_hours2,
total_hours3 = $total_hours3,
total_hours4 = $total_hours4,
total_hours5 = $total_hours5,
hours_subtotal1 = $hours_subtotal1,
hours_subtotal2 = $hours_subtotal2,
hours_subtotal3 = $hours_subtotal3,
hours_subtotal4 = $hours_subtotal4,
hours_subtotal5 = $hours_subtotal5,
total_hours = $total_hours,
material_total = $material_total,
labor_cost = $labor_cost,
grand_total = $grand_total WHERE `id` = '$id'");
mysql_affected_rows();
echo mysql_error();
?>
The code as it is wont post to the database, it displays the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' item_qty1 = , item_qty2 = , item_qty3 = ' at line 1
I was told I don't need apostrophe's or back ticks on my values so I removed them and still get the error. Now I changed my code a bit to remove any similar values, example I removed any value beyond value 1 so item_qty2, item_qty3 and so on I removed so I now have this code:
mysql_query("UPDATE `tickets` SET `work_performed` = '$work_performed',
`item_qty1` = '$item_qty1',
`manuf_1` = '$manuf_1',
`part_number1` = '$part_number1',
`part_description1` = '$part_description1',
`part_price1` = '$part_price1',
`price_extension1` = '$price_extension1',
`material_total` = '$material_total',
`sales_tax` = '$sales_tax',
`shipping_cost` = '$shipping_cost',
`work_date1` = '$work_date1',
`tech_name1` = '$tech_name1',
`cost_code1` = '$cost_code1',
`pay_rate1` = '$pay_rate1',
`total_hours1` = '$total_hours1',
`hours_subtotal1` = '$hours_subtotal1',
`total_hours` = '$total_hours',
`material_total` = '$material_total',
`labor_cost` = '$labor_cost',
`grand_total` = '$grand_total' WHERE `id` = '$id'");
This modified code works flawlessly everytime with no syntax errors and posts to the selected record every single time, but, this wont work for me, I need the additional values OR I need a way for the user to add additional fields to the form if they need to which would solve my problem of not having to enter a value in every field unless they have to. Also if anybody has any examples on how to compress this to make it more "functional" not so bulky I guess, that would be appreciated very much. Thanks!
to just optimize the code, what can be done is :
// define an array of column names and values got from input.
$column_names = array('column1' => $column1, 'column2' => $column2, .....);
// built an sql select clause
$select_clause = array();
foreach ($column_names as $cn => $cn_val) {
if (!empty($cn_val)) {
$select_clause = "{$cn} = {$cn_val}";
}
}
// built proper query
$sql = "UPDATE table_name SET" . implode(',', $select_clause) . " table_name WHERE .....";
// continue with your stuff.