Hi,
I have taken skills form the user in a text box using comma separated values. For eg: Key Skills: C,C++,Java
Now i have stored this vaues into array named arrSkills using explode function. Now before entering them into database i first check in the tagmaster table if already a tagnamed arrSkills exists in the table. If it exists i select the tagId of the corresponding tagname. If it doesnt exists then i first insert that arrSkills into tagmaster and then select its tagId. After the TagId is selected i enter the tagId and username into usertags table. The problem here is that it enters the tagId as the number of elements entered in KeySkill i.e. 3 for above example and tagname as Array in tagmaster table and makes the usertags table go to infinite value.
This is the code that i have used. Plz check out the error and let me know.
[code=php]
$arrSkills = explode(",",$Ke ySkills);
while($arrSkill s != 0){
$query1 = mysql_query("SE LECT TagId FROM tagmaster WHERE TagName = '$arrSkills'") or die(mysql_error ());
$numrow = mysql_num_rows( $query1);
if($numrow == 0){
mysql_query( "INSERT INTO $db_table3(TagN ame)values('$ar rSkills')") or die(mysql_error ());
$query2 = mysql_query("SE LECT TagId FROM tagmaster WHERE TagName = '$arrSkills'") or die(mysql_error ());
$info = mysql_fetch_arr ay($query2);
mysql_query( "INSERT INTO $db_table4(TagI d,UserName)valu es('$info[TagId]','$_POST[UserName]')") or die(mysql_error ());
} //end of if
else{
$info = mysql_fetch_arr ay($query1);
mysql_query( "INSERT INTO $db_table4(TagI d,UserName)valu es('$info[TagId]','$_POST[UserName]')") or die(mysql_error ());
} //end of else
} //end of while
[/code]
I have taken skills form the user in a text box using comma separated values. For eg: Key Skills: C,C++,Java
Now i have stored this vaues into array named arrSkills using explode function. Now before entering them into database i first check in the tagmaster table if already a tagnamed arrSkills exists in the table. If it exists i select the tagId of the corresponding tagname. If it doesnt exists then i first insert that arrSkills into tagmaster and then select its tagId. After the TagId is selected i enter the tagId and username into usertags table. The problem here is that it enters the tagId as the number of elements entered in KeySkill i.e. 3 for above example and tagname as Array in tagmaster table and makes the usertags table go to infinite value.
This is the code that i have used. Plz check out the error and let me know.
[code=php]
$arrSkills = explode(",",$Ke ySkills);
while($arrSkill s != 0){
$query1 = mysql_query("SE LECT TagId FROM tagmaster WHERE TagName = '$arrSkills'") or die(mysql_error ());
$numrow = mysql_num_rows( $query1);
if($numrow == 0){
mysql_query( "INSERT INTO $db_table3(TagN ame)values('$ar rSkills')") or die(mysql_error ());
$query2 = mysql_query("SE LECT TagId FROM tagmaster WHERE TagName = '$arrSkills'") or die(mysql_error ());
$info = mysql_fetch_arr ay($query2);
mysql_query( "INSERT INTO $db_table4(TagI d,UserName)valu es('$info[TagId]','$_POST[UserName]')") or die(mysql_error ());
} //end of if
else{
$info = mysql_fetch_arr ay($query1);
mysql_query( "INSERT INTO $db_table4(TagI d,UserName)valu es('$info[TagId]','$_POST[UserName]')") or die(mysql_error ());
} //end of else
} //end of while
[/code]
Comment