473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to manage foreign key, what php coding i need??

127 100+
I have did the company login and job post which means that company can post the job after they login in my webpage.. I had set company_ID(tablename:company) is foreign key of table job. But when i post the job into database, the company_ID show 0(which means when company register, the company_ID should be 2, for example, but in table job, it show 0). What should i do or what php code should i add to get the correct company_ID in table job. And when the company want to post the job(after login), their contact information should be display in the job post form, so they no need to re-enter their information(because database already have their information after they register). But how to do it?? Below is my login function and php code for job post.. Hope someone can help me.. Thanx..

LOGIN FUNCTION
[PHP]<?php

extract ($_POST);

mysql_connect("localhost","root","")
or die("Cannot connect to the server");

mysql_select_db("ums e-job portal")
or die("Cannot connect to the database");

$sql="select username from company where username='$username'";

$result=mysql_query($sql)
or die("Cannot execute query");

$num=mysql_num_rows($result);


if($num==1) //username valid
{
$sql="select username from company where username='$username' and password='$password'";

$result2=mysql_query($sql)
or die("Cannot execute query");

$num2=mysql_num_rows($result2);
if($num2>0)
{
setcookie("Username", $username, time() + 60 * 60 * 24 * 365);
$today= date("D F d, h:ia");

include("welcome.php");

}
else //message send to emp_login.php when wrong password
{
$message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
include("emp_login.php");
}
}
elseif($num==0) //message send to emp_login.php when username not valid
{
$message="The username you entered does not exist! Please try again.<br>";
include("emp_login.php");
}



?>[/PHP]


JOB POST FUCTION

[PHP]<?php
include_once("database.php");


class user {


function linkid ()
{
$db = new db();
$link_id = $db->dbconnect();

return $link_id;
} // end function linkid

function add_user($arr)
{




$link_id = $this->linkid();

$companyName = $arr['companyName'];
$contactName = $arr['contactName'];
$emailAdd = $arr['emailAdd'];
$contactNum = $arr['contactNum'];
$contactAdd = $arr['contactAdd'];
$jobTitle = $arr['jobTitle'];
$jobType = $arr['jobType'];
$jobCategory = $arr['jobCategory'];
$jobPosition = $arr['jobPosition'];
$jobLocation = $arr['jobLocation'];
$mRequirement = $arr['mRequirement'];
$jobDescription = $arr['jobDescription'];
$datePosted = $arr['datePosted'];


if($companyName==""){
$message="Opps.. You forgot enter your Company Name!<br>";
include("job.php");
}


else


if($contactName==""){
$message="Opps.. You forgot enter your Contact Name!<br>";
include("job.php");
}


else


if($emailAdd==""){
$message="Opps.. You forgot enter your Email Address!<br>";
include("job.php");
}


else


if($contactNum==""){
$message="Opps.. You forgot enter your Contact Number!<br>";
include("job.php");
}


else


if($contactAdd==""){
$message="Opps.. You forgot enter your Contact Address!<br>";
include("job.php");
}


else


if($jobTitle==""){
$message="You need to fill in Title of Your Company's Job!<br>";
include("job.php");
}


else


if($jobType==""){
$message="You need to fill in Type of Your Company's Job!<br>";
include("job.php");
}


else



if($jobCategory==""){
$message="You need to fill in Category of Your Company's Job!<br>";
include("job.php");
}


else



if($jobPosition==""){
$message="You need to fill in Position of Your Company's Job!<br>";
include("job.php");
}


else



if($jobLocation==""){
$message="You need to fill in Location of Your Company's Job!<br>";
include("job.php");
}


else



if($mRequirement==""){
$message="You need to fill in Minimal Requirement of Job!<br>";
include("job.php");
}


else

if($jobDescription==""){
$message="You need to fill in Description of Your Company's Job!<br>";
include("job.php");
}


else


{


$myquery = "INSERT INTO job ( companyName, contactName, emailAdd, contactNum, contactAdd, jobTitle, jobType, jobCategory, jobPosition, jobLocation, mRequirement, jobDescription, datePosted )".
"VALUES ( '$companyName', '$contactName' ,'$emailAdd', '$contactNum', '$contactAdd', '$jobTitle', '$jobType', '$jobCategory', '$jobPosition', '$jobLocation', '$mRequirement', '$jobDescription', now() )";


$result = mysql_query($myquery,$link_id) or die(mysql_error());

include_once("jobpost_success.php");


}
}
}


?>[/PHP]
Jan 27 '07 #1
3 1956
HI ,

foreign key it's possible innodb table engine only.default mysql table engine is Myisam.so when you create table change the table engine inot innodb

u create table in through via phpmyadmin..

select on Table type innodb
Jan 29 '07 #2
bb nicole
127 100+
Thanks first.. I don't really understand, can u explain more detail..
Thanks.. :)
Jan 31 '07 #3
Motoma
3,237 Expert 2GB
Correct me if I am wrong, but you don't set the company_ID anywhere. If this is the case, then when inserting into the job table, you will get the default value for that field, which appears to be 0.
You will need to get a value for company_ID somehow. The standard way to do this would be by having the company table have an autoincrement field, and then getting the last inserted id.
Jan 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tetsuo | last post by:
How do I get Python to work with foreign characters? When I try to print them, I get a unicode error (characters not ASCII). Wasn't unicode invented for the express purpose of working with...
0
by: dcp | last post by:
I just installed the 4.1.0-alpha-max-nt version of MySql and have just started playing around with it. My first test was to try to create a couple of tables, one with a foreign key constraint. ...
2
by: geoff | last post by:
The table creation script(at the end of this post) works fine on 4.0.1-alpha-win, but the foreign key constraints fail on 4.0.15-win. I am starting the server with the same command for both...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
4
by: Tonya | last post by:
Hi, Does anyone have any example of how i can manage forms in my application?? I want to be able to reference my form instances that are currently open from other forms. why cant i open...
0
by: peter | last post by:
I have a Database ( MS Access 2000 ) in which there's 3 Tables(E1_Customer, E2_Supplier and E3_Product). Two Attributes in E1_Customer are the foreign keys of Table E2_Supplier_ID and...
2
by: Aggelos | last post by:
Hello, I am trying to develop a class that I will be able to maintain my relationships dynamically. For example I have the class employee and class company an employ has a Foreign Key companyId...
1
by: Eric Sadoyama | last post by:
I have a database documentation question, but I am not even sure how to phrase it properly so I don't know where to start looking for answers. We are developing a database that is based on...
1
by: apax999 | last post by:
Kinda new to SQL, using SQL Server 2005. I have some foreign keys in a couple of tables. I need to drop these tables, but can't since I'll get the error: Msg 3726, Level 16, State 1, Line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.