Jump to content

Recommended Posts

Okay I have this work order system I not so lovingly refer to as Hades 2.0, I have this work order form that inserts data into two db. works fine, I have an edit workorder page, that recalls a selected order and allows for fields to be changed, this works fine, so what I want to do is allow users to select a certain order and copy it, creating a new order, which I have half working...it submits a new WorkorderID and creates a new order in one table : WorkOrders, but then leaves out fields that must be inserted from the form fields, so my question is should I be looking at the form or is it the sql.  I will attach the code its a big page (is that ok)

It also isn't inserting a record at all into the second table WorkOrderForm...

so is there an easy way to take a edit page and make a new order from it?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/145956-solved-copy-order-problems/
Share on other sites

Hi AllWork,

No things wouldn't be exact, my boss thinks this will help the lazy sales force to not have to fill out all the form fields so the "only" thing that wouldn't change would be the client, the dates and ad etc would possibly change I'm attaching a different file too because the first one was the wrong one.  I think it's either how Im reusing the form or I've got my insert wrong in my sql ... I hate the php has to have all fields in order, or is that sql ..it's a pain.

Hi AllWork,

No things wouldn't be exact, my boss thinks this will help the lazy sales force to not have to fill out all the form fields so the "only" thing that wouldn't change would be the client, the dates and ad etc would possibly change I'm attaching a different file too because the first one was the wrong one.  I think it's either how Im reusing the form or I've got my insert wrong in my sql ... I hate the php has to have all fields in order, or is that sql ..it's a pain.

 

Where's the code?

Yeah that is quite a bit of code...

 

Ok, so create a new page that has all the fields you want. The new EDIT page or COPY page would take in any fields you want already filled in, and for the other fields that you want the lazy sales people to fill in, make those blank...

 

My question is, do the users have the choice of what they want already pulled out of the DB or will that be hardcoded?

Well the users get to make the choice of what they need to change when the form presents with the fields filled in but editable, basically I tried using the edit page and instead of having an UPDATE sql function, I tried to make a new record, only thing is that it is making a new record, like it does creat a new WorkOrderID and timestamp but then does not submit any of the form fields, seems like there should be a way to turn the edit page into a copy page right?

Well the users get to make the choice of what they need to change when the form presents with the fields filled in but editable, basically I tried using the edit page and instead of having an UPDATE sql function, I tried to make a new record, only thing is that it is making a new record, like it does creat a new WorkOrderID and timestamp but then does not submit any of the form fields, seems like there should be a way to turn the edit page into a copy page right?

 

Ok I think I understand what you're trying to do.

 

 

Yeah this should be pretty simple. You are already pulling the data from the DB and presenting it on the form.

Somehow though, the data is getting lost when you are creating the new record.

 

Is it possible that you have UNIQUE tables created that won't allow you to post certain fields that are the same?

 

 

 

 

Is it possible that you have UNIQUE tables created that won't allow you to post certain fields that are the same?

 

 

hmm...pardon my newbieness but i'm not sure what that means, I don't think they are Unique tables (how could I tell)  because I could manually make the order and it would submit.

 

On the good side of things I just got an update from the boss that the only 3 fields that need to be generated for a new/duplicated order, are from her email: "An exact duplicate with new work order number and blank start date, end date and io# "

 

So maybe I can get it to work by making more of the fields...I don't know I'm getting lost on this...it seemed like it should of been so easy to do.

 

Is it possible that you have UNIQUE tables created that won't allow you to post certain fields that are the same?

 

 

hmm...pardon my newbieness but i'm not sure what that means, I don't think they are Unique tables (how could I tell)  because I could manually make the order and it would submit.

 

On the good side of things I just got an update from the boss that the only 3 fields that need to be generated for a new/duplicated order, are from her email: "An exact duplicate with new work order number and blank start date, end date and io# "

 

So maybe I can get it to work by making more of the fields...I don't know I'm getting lost on this...it seemed like it should of been so easy to do.

 

Ok, yeah this is pretty easy really.

 

Depending on the table structure, it might not allow for duplicate data in the fields like this:

 

workorder_id, username, position

 

So workorder_id would be unique, but then the table structure might say that (workorder_id, username) would be a unique combo. So you you can't have say:

 

Workorder ID#: 1000

username: johndoe

 

And another record that's the same:

 

WorkorderID#: 1000

username: johndoe

 

Again, I'm only guessing...

 

You can do a SHOW CREATE "table" in your mysql, to find out how your table is structured...

 

 

Ok so I had some kind of break thru, it is now copying the order all but the fields $Location and $WorkOrderName which are supposed to go into the workorders table .... I'm doing half of a happy dance right now

 

good job! Although I am confused why it's nitpicking which columns it allows you to update?

 

Why is Location and Workordername not being allowed to input?

I know it's odd that those two fields are the problem children, Especially when other fields in that table are being updated fine.  It's got to be maybe a syntax thing or they are out of order on my sql insert...what a pain, I'm sure it's something simple my eyes are overlooking.

I know it's odd that those two fields are the problem children, Especially when other fields in that table are being updated fine.  It's got to be maybe a syntax thing or they are out of order on my sql insert...what a pain, I'm sure it's something simple my eyes are overlooking.

 

I would check how your SQL insert is structured as well as the table stucture itself...again, there could be unique field combo's that it's not allowing....

If fact, I would echo out all the variables that you want to do the INSERT on and start debugging that way...

 

You can just comment out the actual query so you don't end up inserting a bunch of records just for  testing..

 

Once you are getting all the variables you need, then uncomment the query and see if it goes into the DB...

Found the problem I think, it's in my logic (isn't it always...trust me on this hahah) so it's here:

 

$sql2 = "SELECT Location, WorkOrderName FROM workorders WHERE WorkOrderID='$WorkOrderID'";
$result2 = mysql_query ($sql2);
$row2 = mysql_fetch_object($result2);

 

Since I'm creating a new WorkOrderID further up to create the new record with, when it gets to this part and selects location and workordername there is nothing there ...yet what I don't get is that it will echo the values from the Original order...argh no I'm going off in a circle again, I thought the fields were empty, but it echos the values and just won't insert them into the new record just those two fields...those TWO...pulling hair out now

Found the problem I think, it's in my logic (isn't it always...trust me on this hahah) so it's here:

 

$sql2 = "SELECT Location, WorkOrderName FROM workorders WHERE WorkOrderID='$WorkOrderID'";
$result2 = mysql_query ($sql2);
$row2 = mysql_fetch_object($result2);

 

Since I'm creating a new WorkOrderID further up to create the new record with, when it gets to this part and selects location and workordername there is nothing there ...yet what I don't get is that it will echo the values from the Original order...argh no I'm going off in a circle again, I thought the fields were empty, but it echos the values and just won't insert them into the new record just those two fields...those TWO...pulling hair out now

 

 

Great! So you ARE getting the variables, that's the good part so they aren't getting lost...

 

Then it's your INSERT statements..I'm telling you, did you look at your DB structure???

 

Well the one field missing from that sql statement is the WorkOrderID which is an auto increment so should I have it on there...here is a paste from the print view of that table:

Field    Type      Null    Default      Links to    Comments    MIME

WorkOrderID    int(20)    No                   

CreatedDate    datetime    No    0000-00-00 00:00:00               

Location    varchar(150)    No                   

WorkOrderName    varchar(250)    No                   

AdminID    int(20)    No    0               

FormName    varchar(50)    No                   

Status    varchar(50)    No                   

Notes    text    No                   

pod    varchar(55)    No                   

 

 

Indexes:

Keyname    Type    Cardinality    Field

PRIMARY    PRIMARY    19    WorkOrderID

 

Maybe my sql statement needs to be this?:

$sql = "INSERT INTO workorders (WorkOrderID, CreatedDate, Location, WorkOrderName, AdminID, FormName, Status, Notes) VALUES (";
   $sql .= "'$WorkOrderID', Now(), '$Location', '$WorkOrderName', '$AdminID', 'WorkOrder', 'New Order', '$Notes')";
   mysql_query($sql);
   $WorkOrderID = mysql_insert_id();




 

Well to answer my own question no it won't work like that it just keeps logging me out and not copying the order at all....

hmmm, the WorkOrderID is auto_increment so you can take that out, I take it though that you don't have it in there but you just wanted to show me?

 

So it should be:

 

$sql = "INSERT INTO workorders (CreatedDate, Location, WorkOrderName, AdminID, FormName, Status, Notes) VALUES (";
   $sql .= "Now(), '$Location', '$WorkOrderName', '$AdminID', 'WorkOrder', 'New Order', '$Notes')";
   mysql_query($sql);
   $WorkOrderID = mysql_insert_id();

 

BUT, I don't see that WorkOrderID is set to "auto increment" in your table description?

 

 

the WorkOrderID isn't the problem I don' t think because it pulls the order to be copied and it is creating a new record, only when the new record is created all the fields except Location and WorkOrderName are being populated... I'm lost

the WorkOrderID isn't the problem I don' t think because it pulls the order to be copied and it is creating a new record, only when the new record is created all the fields except Location and WorkOrderName are being populated... I'm lost

 

The insert statement looks perfect to me! i can't see any reason why it wouldn't work....

 

especially since you said that you CAN echo out the variables, so they aren't being lost anywhere...

 

mind boggling....

would make it easier if you combined the 2 statements also using proper concatenation with the dots allows you to properly insert $variables into MYSQL without much fuss. ;D

<?php
$sql = "INSERT INTO workorders (CreatedDate, Location, WorkOrderName, AdminID, FormName, Status, Notes) 
VALUES (NOW(), '".$Location."', '".$WorkOrderName."', '".$AdminID."', 'WorkOrder', 'New Order', '".$Notes."')";

   mysql_query($sql) or die(mysql_error());
   $WorkOrderID = mysql_insert_id();

?>

 

 

Nope,  tried your combine Dark, it's a stumper, it still inserts a new work order with everything but those two fields Location and WorkOrderName.....why why.... driving me nuts, literally been working on the same problem for 10 hrs...something has to give ...

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.