· 8 years ago · Aug 31, 2018, 11:44 AM
1Help me remove mysql_insert_id
2/// inserts the blog into blog table.
3$insert = mysql_query("INSERT INTO blogs (id, url, user, pass, dname, islocal, cat2post) VALUES ('', '$blog', '$bloguser', '$blogpassword', '','NO','$_POST[cat2blog]')")or die( 'Error: ' . mysql_error());
4
5$taggit1 = mysql_insert_id();
6
7$page->content .= "<p class="alert">Success - External blog Added!</p>";
8
9/// let's see what tags we have and explode them.
10//$tags = $_POST['tags'] which is an array of words seperated by comma
11$tags = 'fishing';
12$pieces = explode(",", $tags);
13
14/// go through the tags and add to tags table if needed.
15foreach ($pieces as $l){
16$l = trim($l);
17
18$query = "SELECT id FROM tags WHERE tag = '$l'";
19$result = mysql_query($query) or die( "Error: " . mysql_error() . " in query $query");
20$row = mysql_fetch_array($result);
21$taggit2 = $row[0];
22
23if ($taggit2 == '') {
24$insert2 = mysql_query("INSERT INTO tags (id, tag) VALUES ('','$l')")or die( 'Error: ' . mysql_error());
25$taggit2 = mysql_insert_id();
26$page->content .= "<p class="alert">This tag didn't exist - so I inserted a new tag</p>";
27}
28
29/// for each tag we have, let's insert the blogstags table so we can reference which blog goes to which tag. Blogstags_id should map to the id of the blog.
30
31$insert3 = mysql_query("INSERT INTO blogstags (id, tag_id, blogstags_id) VALUES ('','$taggit2','$taggit1')")or die( 'Error: ' . mysql_error());
32
33}
34
35CREATE TABLE IF NOT EXISTS `blogs` (
36 `id` int(11) NOT NULL auto_increment,
37 `url` text NOT NULL,
38 `user` text NOT NULL,
39 `pass` text NOT NULL,
40 `dname` text NOT NULL,
41 `islocal` varchar(3) NOT NULL,
42 `cat2post` int(11) NOT NULL,
43 PRIMARY KEY (`id`)
44) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
45
46
47CREATE TABLE IF NOT EXISTS `blogstags` (
48 `id` int(11) NOT NULL auto_increment,
49 `tag_id` int(11) NOT NULL,
50 `blogstags_id` int(11) NOT NULL,
51 PRIMARY KEY (`id`)
52) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
53
54
55CREATE TABLE IF NOT EXISTS `tags` (
56 `id` int(11) NOT NULL auto_increment,
57 `tag` text NOT NULL,
58 PRIMARY KEY (`id`)
59) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;