Jump to content

[SOLVED] mysql max


chocopi

Recommended Posts

well i have got this but it does not work

 

$query = mysql_query("SELECT `post_num` FROM `zBoard_messages` WHERE board_id='$board' ORDER BY `post_num` DESC LIMIT 1") or die(mysql_error());
$fetch= mysql_fetch_assoc($query) or die(mysql_error());
$psot_num = $fetch['post_num'];
$post_num++;

 

it just inputs 1 into the database

Link to comment
https://forums.phpfreaks.com/topic/55245-solved-mysql-max/#findComment-273054
Share on other sites

cheers but it is still producing one

 

this is my whole code

 

<?php

// Start Session
session_start();
if(!isset($_SESSION['username']) && !isset($_SESSION['id']) && !isset($_SESSION['password']))
{
header("Location: login.php");
} else
{
require_once('page_header.php');
$id = $_SESSION['id'];
$username = $_SESSION['username'];
if($_POST)
{

$poster = $id;
$board = '1';

// get actual message
$original = $_POST['message'];
$text = $original;

require_once('bbcode.php');

$date = date('YmdHia');

$query = mysql_query("SELECT MAX(post_num) FROM `zBoard_messages` WHERE board_id='$board'") or die(mysql_error());
$fetch= mysql_fetch_assoc($query) or die(mysql_error());
$psot_num = $fetch['post_num'];
$post_num++;

$query = "INSERT INTO `zBoard_messages` (poster_id,board_id,post_num,subject,message,date) VALUES ('$poster','$board','$post_num','$subject','$original','$date')";
mysql_query($query) or die(mysql_error());
header("Location: thanks.php");
} else {
?>
<html>
<body>
<form name="name" method="post" action="<?php $PHP_SELF ?>">
<center>
<br />
<input type="text" name="subject" id="subject" value="<?php $subject ?>" />
<br />
<br />
<textarea name="message" value="<?php $original ?>" cols="60" rows="15"></textarea>
<br />
<br />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
</center>
</body>
</html>

<?php

}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/55245-solved-mysql-max/#findComment-273063
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.