Jump to content

inserting another table using same ID


rachae1

Recommended Posts

Hi I am trying to do a tag cloud but I am struggling with adding my tags to the database.

 

I currently have 1 table called link that I use to add my info into the database and that works fine but I am now trying to adapt it with some code from a tutorial so I can use another table for storing tags but it doesn't do anything and I can't figure out why. I was wondering if someone can help me piece it together.

 

if ($submit == 'Add') {
if ($h1 == ""){
	echo forwardScript($href);
	exit;
} else {

	$query  = "INSERT INTO link ";

	$query .= "description ='" . $description . "',";
	$query .= "linkURL ='" . $linkURL . "',";
	$query .= "linkTitle ='" . $linkTitle . "'";

$query_result = domysql($query, 'Adding a link' . $_SERVER['PHP_SELF']); 
	}
}

;

 

The Code from a tutorial for the new table


CREATE TABLE `tags` (
`uid` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`item_id` INT( 11 ) NOT NULL,
`tag` VARCHAR( 50 ) NOT NULL
) ENGINE = MYISAM ;


$taginput = $_POST["tags"];
$tagarray = explode(",",$taginput);

for($i=0;$i<count($tagarray);$i++){
$usetag = mysql_real_escape_string(stripslashes(ltrim(rtrim($tagarray[$i]))));
if($usetag == "") continue;
$query = "INSERT INTO tags (item_id,tag) VALUES ($itemid,'$usetag')";
mysql_query($query);
}


 

 

Now I am guessing that I need to rename the item_id to id as that's what it is labeled in table 1

 

Thanks in advance.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/123752-inserting-another-table-using-same-id/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.