Jump to content

[SOLVED] Query problem? When moving from one table to another....


Recommended Posts

What I am doing: data from a file is put into csv_temp and then compared to csv_data. If the WORK_ORDER_NUMBER already exists it runs a UPDATE query; if it doesn't then it inserts it into csv_data. Seems like it would be easy but when the insert query runs it says I have a problem with it. There can't be a problem with the data itself, since well, it's already in a table. Here is my crappy code. Oh then after it inserts or updates it deletes the row. The error says I have an error in my query. Not sure whats going on...

 

echo 'Record Process Information:<br />';
$query = "SELECT * FROM csv_temp";
$result = mysql_query($query) or trigger_error("Query: $sql\n<br />MySQL Error: " . mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
	$c01 = $row['ACKNOWLEDGED'];
	$c02 = $row['MGT_AREA'];
	$c03 = $row['TECH_NUMBER'];
	$c04 = $row['UNITS'];
	$c05 = $row['CSG_STATUS'];
	$c06 = $row['WORK_ORDER_TYPE'];
	$c07 = $row['CSG_LAST_CHANGED_DATE'];
	$c08 = $row['AUTO_ASSIGNED_TECH_NUMBER'];
	$c09 = $row['SCHEDULED_DATE'];
	$c10 = $row['ACTIVITY'];
	$c11 = $row['CUSTOMER_NAME'];
	$c12 = $row['CUSTOMER_PHONE'];
	$c13 = $row['CSG_ACCT_NUMBER'];
	$c14 = $row['WORK_ORDER_NUMBER'];
	$c15 = $row['IMS_WORK_ORDER_NUMBER'];
	$c16 = $row['MDU'];
	$c17 = $row['CUSTOMER_ADDRESS'];
	$c18 = $row['CUSTOMER_CITY'];
	$c19 = $row['CUSTOMER_ZIP'];
	$c20 = $row['SERVICE_CODES'];
	$c21 = $row['HARDWARE_DELIVERY'];
	$c22 = $row['CLASSES'];
	$c23 = $row['WO_CREATE_DATE'];
	$c24 = $row['WO_INSERT_DATE'];
	$c25 = $row['REASON1'];
	$c26 = $row['REASON2'];
	$c27 = $row['REASON3'];
	$c28 = $row['REASON4'];
	$c29 = $row['RESO1'];
	$c30 = $row['RESO2'];
	$c31 = $row['RESO3'];
	$c32 = $row['RESO4'];
	$c33 = $row['NBU'];
	$c34 = $row['RR_CANDIDATE'];
	$c35 = $row['RBU_WORKED'];
	$c36 = $row['CATEGORY'];
	$c37 = $row['SEGMENT_OUTPUT'];
	$c38 = $row['SECONDARY_PH'];
	$c39 = $row['RETAILER_NAME'];
	$c40 = $row['WORK_ORDER_STATE'];
	$c41 = $row['ROUTE_DATE'];
	$c42 = $row['ROUTE_ID'];
	$c43 = $row['ROUTE_NAME'];
	$c44 = $row['ROUTE_STOP_SEQUENCE'];
	$c45 = $row['USERLOGINID'];
	$c46 = $row['ONSITE_TIME'];
	$c47 = $row['COMPLETE_TIME'];
	$c48 = $row['ESTIMATED_DURATION'];
	$c49 = $row['MILEAGE'];
	$c50 = $row['SCHEDULE_STATUS'];
	$c51 = $row['VAN_DESCRIPTION'];
	$c52 = $row['RADIO_DESCRIPTION'];
	$c53 = $row['PREVIOUS_SCHEDULED_DATE'];
	$c54 = $row['CUSTOMER_STATE'];
	$c55 = $row['TECH_STATE'];
	$c56 = $row['SECOND_ASSIGNED_TECH'];
	$c57 = $row['DISPATCHER_NOTES'];
	$c58 = $row['ACTIVE'];
	$c59 = $row['VISITED'];
	$c60 = $row['LEP'];
	$c61 = $row['DEADLINE'];
	$c62 = $row['AGE'];
	$c63 = $row['PRECALL_STATUS'];
	$c64 = $row['WO_COST'];
	$c65 = $row['ACCT_DESIGNATION'];
	$c66 = $row['COMPASS'];
	$c67 = $row['NETWORKS'];
	$c68 = $row['CHANNELS'];
	$c69 = $row['OTA'];
	$c70 = $row['WB'];

	$qFind = "SELECT * FROM csv_data WHERE WORK_ORDER_NUMBER='$c14'";
	$rFind = mysql_query($qFind) or trigger_error("Query: $qFind\n<br />MySQL Error: " . mysql_error());

	if (mysql_affected_rows() == 1) {
		$qUpdate = "UPDATE csv_data SET ACKNOWLEDGED='$acknowledged',MGT_AREA='$mgt_area',TECH_NUMBER='$tech_number',UNITS='$units',CSG_STATUS='$csg_status',WORK_ORDER_TYPE='$work_order_type',CSG_LAST_CHANGED_DATE='$csg_last_changed_date',AUTO_ASSIGNED_TECH_NUMBER='$auto_assigned_tech_number',SCHEDULED_DATE='$scheduled_date',ACTIVITY='$activity',CUSTOMER_NAME='$customer_name',CUSTOMER_PHONE='$customer_phone',CSG_ACCT_NUMBER='$csg_acct_number',WORK_ORDER_NUMBER='$work_order_number',IMS_WORK_ORDER_NUMBER='$ims_work_order_number',MDU='$mdu',CUSTOMER_ADDRESS='$customer_address',CUSTOMER_CITY='$customer_city',CUSTOMER_ZIP='$customer_zip',SERVICE_CODES='$service_codes',HARDWARE_DELIVERY='$hardware_delivery',CLASSES='$classes';WO_CREATE_DATE='$wo_create_date',WO_INSERT_DATE='$wo_insert_date',REASON1='$reason1',REASON2='$reason2',REASON3='$reason3',REASON4='$reason4',RESO1='$reso1',RESO2='$reso2',RESO3='$reso3',RESO4='$reso4',NBU='$nbu',RR_CANDIDATE='$rr_candidate',RBU_WORKED='$rbu_worked',CATEGORY='$category',SEGMENT_OUTPUT='$segment_output',SECONDARY_PH='$secondary_ph',RETAILER_NAME='$retailer_name',WORK_ORDER_STATE='$work_order_state',ROUTE_DATE='$route_date',ROUTE_ID='$route_id',ROUTE_NAME='$route_name',ROUTE_STOP_SEQUENCE='$route_stop_sequence',USERLOGINID='$userloginid',ONSITE_TIME='$onsite_time',COMPLETE_TIME='$complete_time',ESTIMATED_DURATION='$estimate_duration',MILEAGE='$mileage',SCHEDULE_STATUS='$schedule_status',VAN_DESCRIPTION='$van_description',RADIO_DESCRIPTION='$radio_description',PREVIOUS_SCHEDULED_DATE='$previous_scheduled_date',CUSTOMER_STATE='$customer_state',TECH_STATE='$tech_state',SECOND_ASSIGNED_TECH='$second_assigned_tech',DISPATCHER_NOTES='$dispatcher_notes',ACTIVE='$active',VISITED='$visted',LEP='$lep',DEADLINE='$deadline',AGE='$age',PRECALL_STATUS='$precall_status',WO_COST='$wo_cost',ACCT_DESIGNATION='$acct_designation',COMPASS='$compass',NETWORKS='$networks',CHANNELS='$channels',OTA='$ota',WB='$wb'0 WHERE WORK_ORDER_NUMBER='$work_order_number'";
		$rUpdate = mysql_query($qUpdate) or trigger_error("Query: $qUpdate\n<br />MySQL Error: " . mysql_error());

		echo $work_order_number . ' UPDATED<br />';
	} else {
                        // this below is what is throwing an error itself.
		$qInsert = "INSERT INTO csv_data (ACKNOWLEDGED, MGT_AREA, TECH_NUMBER, UNITS, CSG_STATUS, WORK_ORDER_TYPE, CSG_LAST_CHANGED_DATE, AUTO_ASSIGNED_TECH_NUMBER, SCHEDULED_DATE, ACTIVITY, CUSTOMER_NAME, CUSTOMER_PHONE, CSG_ACCT_NUMBER, WORK_ORDER_NUMBER, IMS_WORK_ORDER_NUMBER, MDU, CUSTOMER_ADDRESS, CUSTOMER_CITY, CUSTOMER_ZIP, SERVICE_CODES, HARDWARE_DELIVERY, CLASSES, WO_CREATE_DATE, WO_INSERT_DATE, REASON1, REASON2, REASON3, REASON4, RESO1, RESO2, RESO3, RESO4, NBU, RR_CANDIDATE, RBU_WORKED, CATEGORY, SEGMENT_OUTPUT, SECONDARY_PH, RETAILER_NAME, WORK_ORDER_STATE, ROUTE_DATE, ROUTE_ID, ROUTE_NAME, ROUTE_STOP_SEQUENCE, USERLOGINID, ONSITE_TIME, COMPLETE_TIME, ESTIMATED_DURATION, MILEAGE, SCHEDULE_STATUS, VAN_DESCRIPTION, RADIO_DESCRIPTION, PREVIOUS_SCHEDULED_DATE, CUSTOMER_STATE, TECH_STATE, SECOND_ASSIGNED_TECH, DISPATCHER_NOTES, ACTIVE, VISITED, LEP, DEADLINE, AGE, PRECALL_STATUS, WO_COST, ACCT_DESIGNATION, COMPASS, NETWORKS, CHANNELS, OTA, WB) VALUES ('$c01','$c02','$c03','$c04','$c05','$c06','$c07','$c08','$c09','$c10','$c11','$c12','$c13','$c14','$c15','$c16','$c17','$c18','$c19','$c20','$c21','$c22','$c23','$c24','$c25','$c26','$c27','$c28','$c29','$c30','$c31','$c32','$c33','$c34','$c35','$c36','$c37','$c38','$c39','$c40','$c41','$c42','$c43','$c44','$c45','$c46','$c47','$c48','$c49','$c50','$c51','$c52','$c53','$c54','$c55','$c56','$c57','$c58','$c59','$c60','$c61','$c62','$c63','$c64','$c65','$c66','$c67','$c68','$c69','$c70')";
		$rInsert = mysql_query($qInsert) or trigger_error("Query: $qInsert\n<br />MySQL Error: " . mysql_error());

		echo $c14 . ' INSERTED<br />';
	}

	$qDelete = "DELETE FROM csv_temp WHERE WORK_ORDER_NUMBER='$c14'";
	$rDelete = mysql_query($qDelete) or trigger_error("Query: $qDelete\n<br />MySQL Error: " . mysql_error());
      } // end of each row function.

I figured out the problem. The software that I am having to use does a .CSV export. Well, whoever wrote the software sucks! It adds =" at the beginning of some entries. I fixed that from the get go. Just figured out there there is a section in it's .csv export that has errors, on every row. So I just make a replace code for it and while it modifies the code it goes ahead and fixes the 3-4 problems.

 

Thanks a bunch anyways.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.