Insert retrieved data from one table to another

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Insert retrieved data from one table to another

Post by stanleycwb »

Hi everyone,
Im a php beginner.
Wat im doing now is to updating the details from one table to another table. I have a update HTML form.
Firstly, i use SELECT statement to retrieve the details and then use INSERT statement to insert the details into another table. Below is my code and i have met some errors.

Code: Select all

 
<!DOCTYPE HTML PUBLIC
  "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1-traditional.dtd">
 
<?php
 
 $conn = mysql_connect("localhost", "xxxx", "xxxxxx");
  if (!$conn)
    {
    die('Could not connect: ' . mysql_error());
    }
mysql_select_db("xxxxxxxxx", $conn);
 
$Stud_ID = $_POST['Stud_ID'];
$Current_Work_Industry = $_POST['Current_Work_Industry'];
$Current_Job_Position = $_POST['Current_Job_Position'];
$Current_Company = $_POST['Current_Company'];
$Current_Department = $_POST['Current_Department'];
$Current_Job_Description = $_POST['Current_Job_Description'];
 
if ($Current_Work_Industry | $Current_Company | $Current_Department | $Current_Job_Description)
{
   $query = "SELECT * FROM student WHERE Stud_ID = '$Stud_ID'";
   $result = mysql_query($query, $conn);
   $row = mysql_fetch_array($result))
 
   $query2 = "INSERT INTO jobhistory (Stud_ID, Work_Industry, Company, Job_Position, Department, Job_Description) VALUES ($row['Stud_ID'],$row['Work_industry'],$row['Job_Position'],$row['Department'],$row['Job_Description'])";
   if (!mysql_query($query2, $conn)
   {
   die('Error: ' . mysql_error());
   } 
}
else {
   die('You have to enter all details of the student current employment details');
}
 
mysql_close($conn);
?>
 
Can anyone help me???
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Insert retrieved data from one table to another

Post by desmi »

Code: Select all

 
<?php
 
$conn = mysql_connect("localhost", "xxxx", "xxxxxx");
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxx", $conn);
 
$Stud_ID = $_POST['Stud_ID'];
$Current_Work_Industry = $_POST['Current_Work_Industry'];
$Current_Job_Position = $_POST['Current_Job_Position'];
$Current_Company = $_POST['Current_Company'];
$Current_Department = $_POST['Current_Department'];
$Current_Job_Description = $_POST['Current_Job_Description'];
 
if ($Current_Work_Industry | $Current_Company | $Current_Department | $Current_Job_Description) {
    $query = "SELECT * FROM student WHERE Stud_ID = '$Stud_ID'";
    $result = mysql_query($query, $conn);
    $row = mysql_fetch_array($result);
 
    $studID = $row['Stud_ID'];
    $workIndustry = $row['Work_industry'];
    $jobPosition = $row['Job_Position'];
    $department = $row['Department'];
    $jobDescription = $row['Job_Description'];
 
    $query2 = "INSERT INTO jobhistory (Stud_ID, Work_Industry, Company, Job_Position, Department, Job_Description) VALUES ($studid, $workIndustry, $jobPosition, $department, $jobDescription)";
    if (!mysql_query($query2, $conn)) {
        die('Error: ' . mysql_error());
    }
} else {
    die('You have to enter all details of the student current employment details');
}
 
mysql_close($conn);
?>
Try this one..

Fixed that mysql_fetch_array a bit, removed one ) and added ;

edit: oops, one last edit :) now it should work
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Insert retrieved data from one table to another

Post by stanleycwb »

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xx\xxx\xxxx\xxxxx\xxxxxx.php on line 28

I dun understand wat's wrong with my code.
Anyone help me???
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Insert retrieved data from one table to another

Post by Jade »

You need to make sure you escape the strings in your variables before you insert them into the database.

$studid = addslashes($studid);
$workIndustry = addslashes($workIndustry);
$jobPosition = addslashes($jobPosition);
$department = addslashes($department);
$jobDescription = addslashes($jobDescription);
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Insert retrieved data from one table to another

Post by stanleycwb »

now it succeeded. But then 2 warnings are been given.

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xx\xxx\xxxx\xxxxx\xxxxxx.php on line 19

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xx\xxx\xxxx\xxxxx\xxxxxx.phpon line 20

And the most important thing is when i went into my database and look, i found out that the coding didnt works because in my jobhistory table, it wasnt updated with the details from another table.

Anyone can guide and help me??
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Insert retrieved data from one table to another

Post by desmi »

Change your mysql_connect to:

Code: Select all

 
mysql_connect("localhost","xxx","xxx") or die("Could not connect:" . mysql_error());
mysql_select_db("xxx") or die("Could not select db:" . mysql_error());
 
And then change your select query like:

Code: Select all

 
$result = mysql_query($query); // leave that ,$conn away
 
and same thing with insert query:

Code: Select all

 
$query2 = "....";
mysql_query($query2) or die("error....");
 
Not sure if thats the problem, but thats the way i use it ;)
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Insert retrieved data from one table to another

Post by desmi »

Jade wrote:You need to make sure you escape the strings in your variables before you insert them into the database.

$studid = addslashes($studid);
$workIndustry = addslashes($workIndustry);
$jobPosition = addslashes($jobPosition);
$department = addslashes($department);
$jobDescription = addslashes($jobDescription);

Oh and you could/should use mysql_real_escape_string($string); instead of addslashes
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Insert retrieved data from one table to another

Post by califdon »

stanleycwb wrote:And the most important thing is when i went into my database and look, i found out that the coding didnt works because in my jobhistory table, it wasnt updated with the details from another table.

Anyone can guide and help me??
I would be interested to know what you are trying to do. This sounds suspiciously like you are duplicating data in different tables instead of having a normal relational database. If you are, it's a very, very bad database design.
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Insert retrieved data from one table to another

Post by stanleycwb »

okay, the idea of duplicating information from 1 table to another is quite simple.
I got 2 tables. 1 is job history table and the other one is current employement table.
If A change a job and wants to enter the new information of his job. We will actually update the information in the current employement table. But for job history table, it will have duplicate entries about the person(example: A) about their existing jobs. So that they could keep records about their jobs. So firstly, the codes should first retrieve the data from the current employment table and insert to job history table before the new information is update in the current employment table.
So my job history table will have multiple columns of the same person and only the start date and end date will differentiate when is the order of the job. There is no primary key of that table so to allow duplicate entires.

Code: Select all

<!DOCTYPE HTML PUBLIC
  "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1-traditional.dtd">
 
<?php
 
 //Connect to MySQL
$con = mysql_connect("localhost", "xx", "xxx");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxx") or die("Could not select db:" . mysql_error());
 
$Stud_ID = $_POST['Stud_ID'];
$Occupation = $_POST['Occupation'];
$Address = $_POST['Address'];
$Stud_OContact = $_POST['Stud_OContact'];
$Stud_HContact = $_POST['Stud_HContact'];
$Stud_HPContact = $_POST['Stud_HPContact'];
$Email = $_POST['Email'];
$Work_Industry = $_POST['Work_Industry'];
$Company = $_POST['Company'];
$Job_Position = $_POST['Job_Position'];
$Department = $_POST['Department'];
$Job_Description = $_POST['Job_Description'];
$Current_Work_Industry = $_POST['Current_Work_Industry'];
$Current_Job_Position = $_POST['Current_Job_Position'];
$Current_Company = $_POST['Current_Company'];
$Current_Department = $_POST['Current_Department'];
$Current_Job_Description = $_POST['Current_Job_Description'];
 
$Stud_ID = mysql_real_escape_string($Stud_ID);
$workIndustry = mysql_real_escape_string($Work_Industry);
$Job_Position = mysql_real_escape_string($Job_Position);
$Company = mysql_real_escape_string($Company);
$Department = mysql_real_escape_string($Department);
$Job_Description = mysql_real_escape_string($Job_Description);
$Current_workIndustry = mysql_real_escape_string($Current_Work_Industry);
$Current_Job_Position = mysql_real_escape_string($Current_Job_Position);
$Current_Company = mysql_real_escape_string($Current_Company);
$Current_Department = mysql_real_escape_string($Current_Department);
$Current_Job_Description = mysql_real_escape_string($Current_Job_Description);
 
if (!$Stud_ID)
    echo 'Please enter Student Number.';
 
if ($Current_Work_Industry | $Current_Company | $Current_Job_Position | $Current_Department | $Current_Job_Description)
{
   $query = "Select * FROM currentemploymentdetail WHERE Stud_ID = '$Stud_ID'";
   $result = mysql_query($query);
   $row = mysql_fetch_array($result);
 
    $studID = $row['Stud_ID'];
    $workIndustry = $row['Work_industry'];
    $company = $row['Company'];
    $jobPosition = $row['Job_Position'];
    $department = $row['Department'];
    $jobDescription = $row['Job_Description'];
 
    $query2 = "INSERT INTO jobhistory (Stud_ID, Work_Industry, Company, Job_Position, Department, Job_Description) VALUES ($studid, $workIndustry, $company, $jobPosition, $department, $jobDescription)";
 
    mysql_query($query2) or die("error....");
}
else {
   die('You have to enter all details of the student current employment details');
}
      
  
if ($Occupation) {
$sql1 = "UPDATE Student SET Occupation='$Occupation' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql1))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Address) {  
$sql2 = "UPDATE Student SET Address='$Address' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql2))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Stud_OContact) {
$sql3 = "UPDATE Student SET Stud_OContact='$Stud_OContact' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql3))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Stud_HContact) {
$sql4 = "UPDATE Student SET Stud_HContact='$Stud_HContact' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql4))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Stud_HPContact) {
$sql5 = "UPDATE Student SET Stud_HPContact='$Stud_HPContact' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql5))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Email) {
$sql6 = "UPDATE Student SET Email='$Email' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql6))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Current_Work_Industry) {
$sql7 = "UPDATE CurrentEmploymentDetail SET Current_Work_Industry='$Current_Work_Industry' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql7))
  {
  die('Error: ' . mysql_error());
  }
} 
 
if ($Current_Job_Position) {
$sql8 = "UPDATE CurrentEmploymentDetail SET Current_Job_Position='$Current_Job_Position' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql8))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Current_Job_Description) {
$sql9 = "UPDATE CurrentEmploymentDetail SET Current_Job_Description='$Current_Job_Description' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql9))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Current_Department) {
$sql10 = "UPDATE CurrentEmploymentDetail SET Current_Department='$Current_Department' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql10))
  {
  die('Error: ' . mysql_error());
  } 
}
 
echo "Student Updated";
mysql_close($con);
?>
 
I followed desmi's suggestion however it doesnt even execute, and even display "error...." which is at line 62. This means that it is unable to excute the insert statement.

But when i changed back to my previous code(haven't remove the $con) and added some if-else statement so to know which codes went wrong.

Code: Select all

<!DOCTYPE HTML PUBLIC
  "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1-traditional.dtd">
 
<?php
 
 //Connect to MySQL
$con = mysql_connect("localhost", "xx", "xxx");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxx") or die("Could not select db:" . mysql_error());
 
$Stud_ID = $_POST['Stud_ID'];
$Occupation = $_POST['Occupation'];
$Address = $_POST['Address'];
$Stud_OContact = $_POST['Stud_OContact'];
$Stud_HContact = $_POST['Stud_HContact'];
$Stud_HPContact = $_POST['Stud_HPContact'];
$Email = $_POST['Email'];
$Work_Industry = $_POST['Work_Industry'];
$Company = $_POST['Company'];
$Job_Position = $_POST['Job_Position'];
$Department = $_POST['Department'];
$Job_Description = $_POST['Job_Description'];
$Current_Work_Industry = $_POST['Current_Work_Industry'];
$Current_Job_Position = $_POST['Current_Job_Position'];
$Current_Company = $_POST['Current_Company'];
$Current_Department = $_POST['Current_Department'];
$Current_Job_Description = $_POST['Current_Job_Description'];
 
$Stud_ID = mysql_real_escape_string($Stud_ID);
$workIndustry = mysql_real_escape_string($Work_Industry);
$Job_Position = mysql_real_escape_string($Job_Position);
$Company = mysql_real_escape_string($Company);
$Department = mysql_real_escape_string($Department);
$Job_Description = mysql_real_escape_string($Job_Description);
$Current_workIndustry = mysql_real_escape_string($Current_Work_Industry);
$Current_Job_Position = mysql_real_escape_string($Current_Job_Position);
$Current_Company = mysql_real_escape_string($Current_Company);
$Current_Department = mysql_real_escape_string($Current_Department);
$Current_Job_Description = mysql_real_escape_string($Current_Job_Description);
 
if (!$Stud_ID)
 
    echo 'Please enter Student Number.';
 
if ($Current_Work_Industry | $Current_Company | $Current_Job_Position | $Current_Department | $Current_Job_Description)
{
   $query = "Select * FROM currentemploymentdetail WHERE Stud_ID = '$Stud_ID'";
   $result = mysql_query($query, $con);
   if ($row = mysql_fetch_array($result)){
      echo "Hello";
   }
   else {
   echo "Oh NO!!!";
   }
    $studID = $row['Stud_ID'];
    $workIndustry = $row['Work_industry'];
    $company = $row['Company'];
    $jobPosition = $row['Job_Position'];
    $department = $row['Department'];
    $jobDescription = $row['Job_Description'];
 
    $query2 = "INSERT INTO jobhistory (Stud_ID, Work_Industry, Company, Job_Position, Department, Job_Description) VALUES ($studid, $workIndustry, $company, $jobPosition, $department, $jobDescription)";
 
    $result2 = mysql_query($query2, $con);
    if ($row2 = mysql_fetch_array($result2)){
      echo "Oh my god";
    }
    else {
    echo "Still doesn't work";
    }
}
else {
   die('You have to enter all details of the student current employment details');
}
      
if ($Occupation) {
$sql1 = "UPDATE Student SET Occupation='$Occupation' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql1, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Address) {  
$sql2 = "UPDATE Student SET Address='$Address' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql2, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Stud_OContact) {
$sql3 = "UPDATE Student SET Stud_OContact='$Stud_OContact' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql3, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Stud_HContact) {
$sql4 = "UPDATE Student SET Stud_HContact='$Stud_HContact' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql4, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Stud_HPContact) {
$sql5 = "UPDATE Student SET Stud_HPContact='$Stud_HPContact' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql5, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Email) {
$sql6 = "UPDATE Student SET Email='$Email' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql6, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Current_Work_Industry) {
$sql7 = "UPDATE CurrentEmploymentDetail SET Current_Work_Industry='$Current_Work_Industry' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql7, $con))
  {
  die('Error: ' . mysql_error());
  }
} 
 
if ($Current_Job_Position) {
$sql8 = "UPDATE CurrentEmploymentDetail SET Current_Job_Position='$Current_Job_Position' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql8, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Current_Job_Description) {
$sql9 = "UPDATE CurrentEmploymentDetail SET Current_Job_Description='$Current_Job_Description' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql9, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
 
if ($Current_Department) {
$sql10 = "UPDATE CurrentEmploymentDetail SET Current_Department='$Current_Department' WHERE Stud_ID='$Stud_ID'";
if(!mysql_query($sql10, $con))
  {
  die('Error: ' . mysql_error());
  } 
}
echo "Student Updated";
 
mysql_close($con);
?>
It display the following ouput.
Hello
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xx\xxx\xxxx\xxxxx\xxxxxx.php on line 72
Still doesn't workStudent Updated

This means that my select statement works but not for my insert statement. Which will leads to new information are updated to the database but the job history table still remain the same.

What's wrong with my codes?
Can anyone help me??
Last edited by stanleycwb on Tue Aug 19, 2008 10:30 pm, edited 1 time in total.
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Insert retrieved data from one table to another

Post by stanleycwb »

And another thing is u might be confused with my column names.

jobhistory table(Stud_ID, Work_Industry, Company, Job_Position, Department, Job_Description)

currentemploymentdetail table(Stud_ID, Current_Work_Industry, Current_Company, Current_Job_Position, Current_Department, Current_Job_Description)


$studID = $row['Stud_ID'];
$workIndustry = $row['Current_Work_industry'];
$company = $row['Current_Company'];
$jobPosition = $row['Current_Job_Position'];
$department = $row['Current_Department'];
$jobDescription = $row['Current_Job_Description'];

"INSERT INTO jobhistory (Stud_ID, Work_Industry, Company, Job_Position, Department, Job_Description) VALUES ($studid, $workIndustry, $company, $jobPosition, $department, $jobDescription)";

And below is my update form html.

Code: Select all

<!DOCTYPE HTML PUBLIC
  "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1-traditional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en>
<head>
<meta http-equiv="content-type" content=text/html; charset=iso-8859-1" />
 
<title>Student Update Form</title></head>
</table>
<body> 
 
<p align="center"><table>
<h1>Student Update Form</h1>
<h4>Please fill in the details below. Fields with * denotes mandatory field.</h4>
 
<form action="xxxx.php" method="post">
 
*Admission No.: <input type="text" name="Stud_ID" />        
 
<h3>Particulars</h3>
 
Occupation: 
<select name="Occupation">
<option value="">- - - - - - - - - - - - -</option>
<option value="Student">Student</option>
<option value="Housewife">Housewife</option>
<option value="Employed">Employed</option>
<option value="Self-Employed">Self-Employed</option>
<option value="Unemployed">Unemployed</option>
<option value="Retired">Retired</option>
<option value="Others">Others</option></select><br />
 
Address: <input type="text" name="Address" size="82" /><br />
 
Contact: <input type="text" name="Stud_OContact" />(O) <input type="text" name="Stud_HPContact" />(HP) <input type="text" name="Stud_HContact" />(H)<br />
 
E-Mail Address: <input type="text" name="Email" size="74" /><br />
 
<h3>Current Employment Details</h3>
Job Start Date (yyyy/mm/dd): <input type="text" name="Current_Start_Date"><br />
 
Working Industry: <input type="text" name="Current_Work_Industry" size="29" />
Company: <input type="text" name="Current_Company" size="29" /><br />
 
Job Position: <input type="text" name="Current_Job_Position" size="30" />
Department: <input type="text" name="Current_Department" size="30" /><br />
 
Job Description:<br /><textarea name="Current_Job_Description" cols="70" rows="3" wrap="hard"></textarea><br /><br />
 
<input type="submit" value="Submit">
<input type="reset" value="Clear">
 
</table></p>
</form> 
</body> 
</html>
 
Are my codings wrong? (I think it is otherwise my codes works long ago)
Help me please!!!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Insert retrieved data from one table to another

Post by califdon »

I was afraid that's what you were trying to do. That's 100% wrong for a relational database.

You have two entities, Employees and Jobs. Each should be a separate table. There should never be any Jobs data (not even the current job) in the Employees table. The two tables should be related by the Employee's ID. Whenever you want to see an employee's current job, you just join the tables and select only the Jobs record with the latest date for that employee's ID. For history, you have all of them to view. It is horribly bad design practice to shift data around from table to table, and even more importantly, it makes it quite complicated to extract data from two tables that have similar information. For example, how would you generate a report that summarized the number of months an employee had worked at all jobs combined? Very awkward.
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Insert retrieved data from one table to another

Post by stanleycwb »

hmm okayy. I get your point. And i decided to change my database tables according to what you mentioned.
But for my learning, is it possible to tell me where is my mistakes and errors why my codes doesn't work?
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Insert retrieved data from one table to another

Post by stanleycwb »

oh ya, and one more thing i need help.

if ($Work_Industry | $Company | $Job_Position | $Department | $Job_Description)
{
.
.
.
}

This codes mean the fields in the work category must be filled in.
But i think this is not wat i wanted. There are other fields like the name, address, phone number which are optional to fill in This same goes to the work category. But then i want it in a way where they cant just fill in any one of them like only in work industry and not company and other else. What i want is either the user fill in all the details or dun fill in at all. if the user fill in one of them only, we will display error.

Can help me with this problem?
thanks!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Insert retrieved data from one table to another

Post by califdon »

stanleycwb wrote:hmm okayy. I get your point. And i decided to change my database tables according to what you mentioned.
But for my learning, is it possible to tell me where is my mistakes and errors why my codes doesn't work?
Since you are making substantial changes in your data structure, I would not waste time (yours or mine) trying to debug the old, now obsolete, script. Make your database changes and start again, because the logic will be entirely different.
if ($Work_Industry | $Company | $Job_Position | $Department | $Job_Description)
{
.
.
.
}

This codes mean the fields in the work category must be filled in.
But i think this is not wat i wanted. There are other fields like the name, address, phone number which are optional to fill in This same goes to the work category. But then i want it in a way where they cant just fill in any one of them like only in work industry and not company and other else. What i want is either the user fill in all the details or dun fill in at all. if the user fill in one of them only, we will display error.
Your code syntax makes no sense. What you want to do is called form validation and is a large topic. Look up that topic in the search box in this forum and in Google (use search terms like form validation).
Post Reply