Goldeneye Posted May 9, 2008 Share Posted May 9, 2008 So I'm writing a forum and in the `messages` table there's the `topicid` field which is not auto-incremented which is used by create.php?node=topic&board=*. So how would get the auto-incremented `topicid` from the `topics` table to the `messages table? Is there anyway to do it without a SELECT query? <?php if($_GET['node'] == 'topic'){ if($_GET['board'] == $boardnum){ gHeader('Create a Topic'); if (isset($_POST['createtopic'])) { if(empty($_POST['message'])) { echo 'You missed a field..<br><br>'; } else { mysql_query("INSERT INTO `boardmessages` (`topicid`, `message`, `from`, `userid`, `deleted`, `ip`, `time`) VALUES ('`topicid`+1', '" . $_POST['message'] . "', '" . $namerow['username'] . "', '" . $_SESSION['user_id'] . "', 0, '" . $_SERVER['REMOTE_ADDR'] . "', '" . time() . "')"); mysql_query("INSERT INTO `boardtopics` (`topicid`, `title`, `creator`, `lastpost`, `created`, `userid`, `board`, `pinned`, `closed`, `archived`, `favorites`, `messages`) VALUES ('`topicid`+1', '" . $_POST['title'] . "', '" . $namerow['username'] . "', '" . time() . "', '" . time() . "', '" . $_SESSION['user_id'] . "', '" . $boardnum . "', 0, 0, 0, 0, 1)") || die(mysql_error()); mysql_query("UPDATE `boards` SET `messages`=`messages`+1, `topics`=`topics`+1, `lastpost`=" . time() . " WHERE `boardnum`=" . $boardnum . ""); echo 'THanks for posting! <a href="topiclist.php?board=' . $boardnum . '">Return</a> to the board.<br><br>'; } } if (!isset($_POST['createtopic'])){ echo '<ul class="subnavul"><li class="subnavli"><a href="boardlist.php">Board List</a></li>'; echo '<li class="subnavli"><a href="topiclist.php?board=' . $boardnum . '" target="_blank"><b>Topic List</b></a></li>'; echo '</ul>'; echo '<form action="?node=topic&board=' . $boardnum . '" method="POST">'; echo 'Title:<br><input type="type" name="title" class="textfieldlong"><br><br>'; echo 'Message:<br><textarea rows="5" name="message" class="inputbox"></textarea><br>'; echo '<input type="hidden" name="topid">'; echo '<input type="submit" value="Create Topic" name="createtopic" class="button">'; echo '</form>'; } gFooter(); } } ?> A preemptive thanks... Link to comment https://forums.phpfreaks.com/topic/104938-solved-updating-a-non-auto-increment-column-without-a-_get-value/ Share on other sites More sharing options...
Goldeneye Posted May 10, 2008 Author Share Posted May 10, 2008 So no one knows how to do it? Link to comment https://forums.phpfreaks.com/topic/104938-solved-updating-a-non-auto-increment-column-without-a-_get-value/#findComment-537657 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 I think you want mysql_insert_id(). It gets the last auto-incremented inserted ID on that particular connection (so there's no conflict between multiple topic creations from different people). Link to comment https://forums.phpfreaks.com/topic/104938-solved-updating-a-non-auto-increment-column-without-a-_get-value/#findComment-537659 Share on other sites More sharing options...
BlueSkyIS Posted May 10, 2008 Share Posted May 10, 2008 RE: Updating a non-auto-increment column without a $_GET value what is updating the non-auto-incremented column? Link to comment https://forums.phpfreaks.com/topic/104938-solved-updating-a-non-auto-increment-column-without-a-_get-value/#findComment-537667 Share on other sites More sharing options...
Goldeneye Posted May 10, 2008 Author Share Posted May 10, 2008 Thanks to you DarkWater, it worked! I was looking at another way of doing it on someone else's script, but it was much more complex. This will work just fine. To BlueSky: The `topicid` in `boardtopics` is auto-incremented but the `topicid` in `boardmessages` isn't; and I was looking to update the `topicid` in `boardmessages` with the same `topicid` that was inserted into `boardtopics` via an INSERT query. Link to comment https://forums.phpfreaks.com/topic/104938-solved-updating-a-non-auto-increment-column-without-a-_get-value/#findComment-537670 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 Any time. =) Link to comment https://forums.phpfreaks.com/topic/104938-solved-updating-a-non-auto-increment-column-without-a-_get-value/#findComment-537671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.