「topicid」列から最大の数値を取得する必要があります。以下のスニペットは正常に機能しているようですが、whileループがない場合でも、より良い解決策があるかどうか疑問に思っていました。
<?php
$tquery = "SELECT MAX(topicid) FROM post";
$tresult = mysqli_query($connect,$tquery);
while($row = mysqli_fetch_array($tresult)){
$topidcount = $row['MAX(topicid)'] +1;
?>
<input type="hidden" name="topicid" value="<?php echo $topidcount;?>" />
<?php
}
?>