I need help. Scroll to the bottom of the code for my objective...
I have a flat-file database for news... here's the code:
<?
if($HTTP_POST_VARS['submit']) {
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news.";
exit;
}
if(strstr($HTTP_POST_VARS['title'],"|")) {
echo "Title cannot contain the pipe symbol: |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol: |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['title'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
}
?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Title:<BR>
<INPUT TYPE="text" SIZE="30" NAME="title"><BR>
Article:<BR>
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it dood!"><BR>
</FORM>
That will add a line of news/blog to the text file 'news.txt'. Now I know that I want to include a hidden input in the for for IDs, but I don't know how to make it auto_increment like in MySQL, which I am more familiar with, but do not have access to for this project.
Can anyone help? I just want to give each line an automatically incrementing ID and then be able to call each line by ID for editing and viewing.
Thanks!