This topic is locked
[SOLVED]

 Can't seem to copy field data over to another table

10/13/2010 8:22:22 PM
PHPRunner General questions
K
karmacomposer author

So, now recruiters login and add a record.
I have added an event to the AFTER RECORD ADDED on both the add and edit pages.
I have a Recruiter Table and the two fields (RecruiterID and Recruiting Company Name). I want to insert into another table called RecruiterNames that also has two possible fields (Recruiter ID and CompName)
Here's the code:
global $conn,$strRecruiters;

$strSQLSave = "INSERT INTO RecruiterNames (RecruiterID, CompName) values (";

$strSQLSave .= $values["RecruiterID"].",";

$strSQLSave .= $values["Recruiting Company Name"];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
Here is the PHP error I am getting:
Technical information

Error type 256

Error description Unknown column 'Mfelkerco' in 'field list'

URL url/acesDBtemp/Recruiters_add.php?

Error file /database path/include/dbconnection.php

Error line 36

SQL query INSERT INTO RecruiterNames (RecruiterID, CompName) values (26,Mfelkerco)
For privacy reasons, I changed the actual url to the word url and the actual database path to the word database path.
What am I doing wrong?
Mike

Sergey Kornilov admin 10/13/2010

You forgetting to add single quotes around text values in SQL Query.
See this for a reference:

http://www.webcheatsheet.com/sql/interactive_sql_tutorial/sql_insert.php

K
karmacomposer author 10/14/2010



You forgetting to add single quotes around text values in SQL Query.
See this for a reference:

http://www.webcheatsheet.com/sql/interactive_sql_tutorial/sql_insert.php


Grrrrrrr. I've tried every permutation of single and double quotes and I STILL get the PHP error. I KNOW I'm close and I can almost see the way it should be, but I keep getting:
Technical information

Error type 256

Error description Unknown column 'Mfelkerco' in 'field list'

URL URL/Recruiters_add.php?

Error file Database Path/include/dbconnection.php

Error line 36

SQL query INSERT INTO RecruiterNames (RecruiterID, CompName) values (26,Mfelkerco)
My code is as follows:
global $conn,$strRecruiters;

$strSQLSave = "INSERT INTO RecruiterNames (RecruiterID, CompName) values (";

$strSQLSave .= $values['RecruiterID'].",";

$strSQLSave .= $values["Recruiting Company Name"];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
It seems to have problems with the CompName field. Also, the RecruiterNames field is set to autonumber - should I turn that off?
Mike

Sergey Kornilov admin 10/14/2010

Here is your current query:

INSERT INTO RecruiterNames (RecruiterID, CompName) values (26,Mfelkerco)
It should be this way:

INSERT INTO RecruiterNames (RecruiterID, CompName) values (26,'Mfelkerco')
Unfortunately you cannot guess the syntax. You need to understand exactly what you doing.
Btw, using DAL can save you a few gray hair.

http://xlinesoft.com/phprunner/docs/data_access_layer.htm

Check Add() function.

K
karmacomposer author 10/14/2010



Here is your current query:

INSERT INTO RecruiterNames (RecruiterID, CompName) values (26,Mfelkerco)
It should be this way:

INSERT INTO RecruiterNames (RecruiterID, CompName) values (26,'Mfelkerco')
Unfortunately you cannot guess the syntax. You need to understand exactly what you doing.
Btw, using DAL can save you a few gray hair.

http://xlinesoft.com/phprunner/docs/data_access_layer.htm

Check Add() function.


Yeah, I do not know SQL, but I have programmed other languages. DAL sounds like a better way for me to work.
global $dal;

$tblEvents = $dal->Table("RecruiterNames");

$tblEvents->Value["RecruiterID"]="RecruiterID value from Recruiter table here";

$tblEvents->Value["CompName"]="Recruiting Company Name from Recruiter table here";

$tblEvents->Add();
In the above DAL code, how do I ask for the Recruiter Table and RecruiterID? Same with the second field? It only shows how to hard code the answer. This needs to happen after a Recruiter fills out a form (adds their record) for the first time, or edits it in some way. This action will create a table that can be used as a drop down list for another form (as a lookup table). Each recruiter that logs in and fills out the recruiter form becomes another entry in the RecruiterNames table. At least, that's how it's supposed to work.
I understand that it is PHP code and not SQL. Do I put DAL code in the same events area, or is there a special place for me to put that?
Mike

K
karmacomposer author 10/14/2010

I really want to thank the support staff for what I consider to be excellent support thus far.
That said, I really need to get this solved, so if anyone can just help me get this one thing done, I would be immensely appreciative.
Mike

K
karmacomposer author 10/15/2010

global $dal;

$tblEvents = $dal->Table("RecruiterNames");

$tblEvents->Value["RecruiterID"]=Table("Recruiters")"."'RecruiterID';

$tblEvents->Value["CompName"]=Table("Recruiters")"."'Recruiting Company Name';

$tblEvents->Add();
Am I even close?
I assume I put this in the AFTER RECORD UPDATED event. Yes/No?
Mike

K
karmacomposer author 10/15/2010

On the off chance that it may work, I tried the following:
global $dal;

$tblEvents = $dal->Table("RecruiterNames");

$tblEvents->Value["RecruiterID"]="1";

$tblEvents->Value["CompName"]="Mfelkerco";

$tblEvents->Add();
It worked!!! So, hard coding the ID and name worked. Now, what is the proper syntax for writing the table Recruiters with the field names RecruiterID and Recruiting Company Name. That is all I need to finally get this to a point where my client can start entering data.
I looked up DAL on google and received far too many possibilities to be fruitful. There is no explantion of noteable worth in the manual except that it gives you the code above. However, that does not help when you are trying to write fields from one table into another.
Thank you in advance for help.
Mike

Sergey Kornilov admin 10/15/2010

Mike,
you already have all what you need. Look back at your SQL-based code where you access values of table fields.

K
karmacomposer author 10/15/2010



Mike,
you already have all what you need. Look back at your SQL-based code where you access values of table fields.


So SQL syntax works with DAL?
Mike

K
karmacomposer author 10/15/2010



Mike,
you already have all what you need. Look back at your SQL-based code where you access values of table fields.


Do me one favor and i'll shut up.
Write one damn line of code (one for the ID, which is an integer, and the other, which is text) so I know what to type for the rest of everything:
$tblEvents->Value["RecruiterID"]="RecruiterID"; //needs to access Recruiter table for this field

$tblEvents->Value["CompName"]="Recruiting Company Name"; //needs to access Recruiter table for this field
I will be able to figure out much of what I need to do from that. I studied this entire post and just do not see what you are leading me to. I am not asking for people to write this for me, but when the manual barely glosses over these commands, for example:
=================================================================
Data Access Layer functions
Insert/Update/Delete functions are used to add/edit/delete record(s) in the database.

  1. Add() - inserts a new record into the database
    PHP code:

    global $dal;

    $tblEvents = $dal->Table("EventsTable");

    $tblEvents->Value["event"]="First event";

    $tblEvents->Value["public"]="yes";

    $tblEvents->Add();
    SQL query:

    Insert into EventsTable (event,public) values ('First event','yes')
    =================================================================
    From this example, I can see how to hard code the two values ("First event" and "yes"), but there is no mention of using other tables and the fields in other tables. Rarely does one hard codes stuff in, so these kinds of examples are almost useless for someone unfamiliar with DAL. Also, you then have SQL Query after that. Do we ALSO use that, or is that for reference????
    It's all very confusing. Now, take that along with the HOURS I have waited in between questions and you can see why I am pulling my hair out right now.
    I am NOT a SQL programmer, but have programmed other languages and in every case, I had to read the manual or book on how to program it. That is how I learned the syntax of the language. I have YET to find a manual for DAL and SQL is totally confusing to me.
    Anyway, I just want to know how to write the code to access the value of the field in a separate table.
    RecruiterNames contains RecruiterID and CompName as fields.
    The fields I need to write to the RecruiterNames table comes from the Recruiters table and the fields in question are RecruiterID and Recruiting Company Name (with spaces for readability on the form).
    Now, I have successfully edited the code (no big deal) to hardcode a "1" and "Mfelkerco"
    Great, but that does me no good. I need, now, to tell the code block to access the other table and extract the two fields I need.
    That is all I need right now.
    I appreciate the help and am desperate to get this little damn thing done.
    Mike

T
tedwilder 10/16/2010

Great, but that does me no good. I need, now, to tell the code block to access the other table and extract the two fields I need



hello. well if you remeber this topic : http://www.asprunner.com/forums/topic/15454-query-a-table-for-data/

it's just what you need :

you access the other table , and extract 2 fileds
sql="select * from thetablenameyouneed where somefield=".$_Session["somefield"];

$rs=CustomQuery($sql);

$datafromtheothertable=db_fetch_array($rs);

you will get in $datafromtheothertable["field1"] and $datafromtheothertabl["field2"]
THEN you insert data in the first table. you have so far extracted the 2 fields you need.

just insert them :
global $conn,$strRecruiters;

$strSQLSave = "INSERT INTO RecruiterNames (RecruiterID, CompName) values (";

$strSQLSave .= $datafromtheothertable["field1"].",";

$strSQLSave .= $datafromtheothertable["field2"];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
that is just the idea of what you should do. (sorry i dont know how to use dal ). but try with phpmyadmin or navicat lite ( free) your sql statemetn before coding it with variable. that will sapre you lot of time.

K
karmacomposer author 10/16/2010

Thank you for your answer. TBH, I would like to do this in DAL so that I can replicate it for other tasks.
Mike

K
karmacomposer author 10/16/2010

Okay, I now have no errors and it is writing to table RecruiterNames, but no actual data. Here is my code:
global $dal;
$tblRecs = $dal->Table("Recruiters");

$rs = $tblRecs->Query("Recruiting_Company_Name","RecruiterID");

$RecData = db_fetch_array($rs);
$tblRecs = $dal->Table("RecruiterNames");

$tblRecs->Value["RecName"]= $RecData["Recruiting_Company_Name"];

$tblRecs->Value["RecNum"]= $RecData["RecruiterID"];

$tblRecs->Add();
What is wrong and why does it not work?
Mike

K
karmacomposer author 10/16/2010



hello. well if you remeber this topic : http://www.asprunner.com/forums/topic/15454-query-a-table-for-data/

it's just what you need :

you access the other table , and extract 2 fileds
sql="select * from thetablenameyouneed where somefield=".$_Session["somefield"];

$rs=CustomQuery($sql);

$datafromtheothertable=db_fetch_array($rs);

you will get in $datafromtheothertable["field1"] and $datafromtheothertabl["field2"]
THEN you insert data in the first table. you have so far extracted the 2 fields you need.

just insert them :
global $conn,$strRecruiters;

$strSQLSave = "INSERT INTO RecruiterNames (RecruiterID, CompName) values (";

$strSQLSave .= $datafromtheothertable["field1"].",";

$strSQLSave .= $datafromtheothertable["field2"];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
that is just the idea of what you should do. (sorry i dont know how to use dal ). but try with phpmyadmin or navicat lite ( free) your sql statemetn before coding it with variable. that will sapre you lot of time.


I decided to try your code block. Here is what I changed:
$sql="select * from Recruiters where Recruiting_Company_Name=".$_Session["Recruiting_Company_Name"];

$rs=CustomQuery($sql);

$RecData=db_fetch_array($rs);
global $conn,$strRecruiters;

$strSQLSave = "INSERT INTO RecruiterNames (RecName,RecNum) values (";

$strSQLSave .= $RecData["RecName"].",";

$strSQLSave .= $RecData["RecNum"];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn)
However, I get a php undefined variable error with $_Session and I am not sure if the field Recruiting_Company_Name is the right one. Is that supposed to be a field or a variable?
Thank you for your help.
Mike

D
Dale 10/16/2010

$_Session try $_SESSION

K
karmacomposer author 10/16/2010



$_Session try $_SESSION


That did not work and now I cannot add or edit any records. I rebooted the server, reset all the forms in phprunner, deleted all files and re-uploaded a fresh build and re-started the mysql service and nothing has worked.
So now I cannot edit or add data, but I also do not get php errors. I press save and nothing happens. Any suggestions?
Mike

K
karmacomposer author 10/16/2010

OK, now I have that fixed - I had to duplicate the table in PHPMyAdmin and then make all necessary edits in PHPRunner and upload.
Whew. Now back to trying to get this code to work in the new table.
Mike

K
karmacomposer author 10/17/2010

OK. I put that code along with $_SESSION in place in PHPRunner at AFTER RECORD UPDATED on both ADD and EDIT and I get the following 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 '' at line 1
Here is the code block:
$sql="select from RecruiterData where Recruiting_Company_Name=".$_SESSION["Recruiting_Company_Name"];

$rs=CustomQuery($sql);

$RecData=db_fetch_array($rs);
global $conn,$strRecruiterData;

$strSQLSave = "INSERT INTO RecruiterNames (RecName,RecNum) values (";

$strSQLSave .= $RecData["RecName"].",";

$strSQLSave .= $RecData["RecNum"];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn)
So, something is wrong in this line:
$sql="select
from RecruiterData where Recruiting_Company_Name=".$_SESSION["Recruiting_Company_Name"];
Any new suggestions?
If it helps, here is the MySQL server info:
Server: Localhost via UNIX socket

Server version: 5.0.91-community

Protocol version: 10
Mike

K
karmacomposer author 10/17/2010

I found some errors and made the changes
$sqldata="SELECT

RecruiterID,

Recruiting_Company_Name

FROM RecruiterData WHERE 1";
$rs=CustomQuery($sqldata);

$RecData=db_fetch_array($rs);
global $conn,$strRecruiterNames;

$strSQLSave = "INSERT INTO RecruiterNames (RecruiterID,RecName) values (";

$strSQLSave .= $RecData["RecruiterID"].",";

$strSQLSave .= $RecData['Recruiting_Company_Name'];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
uploaded and now I get this error:
Error type 256

Error description Unknown column 'Mfelkerco' in 'field list'

URL url/RecruiterData_add.php?

Error file /path to database/include/dbconnection.php

Error line 36

SQL query INSERT INTO RecruiterNames (RecruiterID,RecName) values (27,Mfelkerco)

More info
Call stack

File: line Function Arguments

0. include/dbconnection.php:36 db_query 1. INSERT INTO RecruiterNames (RecruiterID,RecName) values (27,Mfelkerco);

  1. Resource id #10;

    1. include/dbconnection.php:47 db_exec 1. INSERT INTO RecruiterNames (RecruiterID,RecName) values (27,Mfelkerco);


  2. Resource id #10;

    2. include/RecruiterData_events.php:30 AfterAdd 1. Array ( [Recruiting_Company_Name] => Mfelkerco [Recruiting Company Home Country Location] => United States [Recruiting Company Owners Name] => Missy Felker [Recruiting Company Website]...;


  3. Array ( [RecruiterID] => 27 ) ;
  4. 0;

    3. RecruiterData_add.php:533 Global scope N/A



    As you can see, the query is CORRECT. It asked for the RecruiterID (equals 27) and the Recruiting_Company_Name (equals Mfelkerco).

    It tries to insert the data into the other table: INSERT INTO RecruiterNames (RecruiterID,RecName) values (27,Mfelkerco)

    That is the correct values going into the correct fields from the correct table.

    However, it cannot write it for some reason, citing that Mfelkerco is not a known column (no it's not - it's a field).
    I am close on this one.
    Mike



T
tedwilder 10/17/2010






hello yes it's $values["yourindexfield"] ( not session )

in fact it's the field based on which you can get the 2 others fields.

example : you have a table "order " with orderid,customer_name,totalamount. to get amount and customer name you use the primary key (index)field , here it's the order id. in your case you have to determined what is the common field between your 2 tables that will return only 1 result.

so you will do
sql="select * from order where orderid=".$values["orderid"];

$rs=CustomQuery($sql);

$datafromorder=db_fetch_array($rs);
then you can insert the amount and customer number in another table.. like table lastorder for instance

global $conn,$strRecruiters;
$strSQLSave = "INSERT INTO lastorder (customer,amount) values (";

$strSQLSave .= $datafromorder["customer_name"].",";

$strSQLSave .= $datafromorder["totalamount"];

$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
I can only give you example that you have to adapt to your special requirements because I have unfortunlatly no time to look more closely to your fields names.

T
tedwilder 10/17/2010

query INSERT INTO RecruiterNames (RecruiterID,RecName) values (27,Mfelkerco)



that the same problem as at the bigniing you forget the " ' "around " Mfelkerco

if in phpmyadmin you try to execute query INSERT INTO RecruiterNames (RecruiterID,RecName) values (27,Mfelkerco)

you will get error. because you have to put " ' " around the text value

query INSERT INTO RecruiterNames (RecruiterID,RecName) values (27,'Mfelkerco')

so in your code you have to add :" ' " around.

to do so you hav to use ascii character because php will do an error ( I had same problem thats how I made it worked).
$strSQLSave .= chr(34).$RecData['Recruiting_Company_Name'].chr(34);
that should work.

K
karmacomposer author 10/17/2010

Nevermind

K
karmacomposer author 10/17/2010

Thank you so much.
That did it!!!!!!!
It works. The CHR ASCII was it! I'm really rusty after not programming for over 11 years, but yes, I forgot that you always need "" with a string. Thank you so much.
I can now finally close this thread.
Mike