Click to See Complete Forum and Search --> : trouble giving forum post unique ID


ksamann
11-06-2007, 03:38 PM
Hello, I am writing a piece of code that post information from a form into a database. There is only one problem: when i have posted 10 different posts, my code gives the next post an id of 2. Like its not reading the whole number just the first digit. Here is the part of the code that gathers information about the highest unique ID and then gives the next post an id that is one number higher.


sql="SELECT UnID AS UnID FROM sfjbue ORDER BY UnID DESC LIMIT 1"

rs.Open sql, conn

Rompe=rs.Fields("UnID").Value
rs.close

rs.Open"SELECT * FROM sfjbue", conn


Antall=rompe+1
PostID="post_" & antall
UnID=antall
Navn=Request.Form("navn")
Kategori=Request.Form("kategori")
Overskrift=Request.Form("overskrift")
Intro=Request.Form("intro")
Tekst=Request.Form("tekst")
BildeURL=Request.Form("bilde")
Dato=FormatDateTime(date(), vblongdate)
Tid=FormatDateTime(now(),vblongtime)
%>

<%
sql="insert into sfjbue(PostID, UnID, Kategori, Navn, Overskrift, Intro, Tekst, BildeURL, Dato, Tid )values('" & PostID & "', '" & UnID & "', '" & Kategori & "', '" & Navn & "', '" & Overskrift & "', '" & Intro & "', '" & Tekst & "', '" & BiildeURL & "', '" & Dato & "', '" & Tid & "')"

conn.Execute sql



rs.close
conn.close

can some bright head figure this out for me. Please comment if I did not make myself clear.

thanks in advance

ksamann

ksamann
11-07-2007, 09:32 AM
Perhaps I did not make it understandable. The code connects to my db and fetching the highest number in my unique id colummn. Then I create a variable and gives it the value of that unique id number. Then i create a new variable and give it the value of the first variable + 1. That should give the new variable a number that is 1 higher than the first. This works all fine until i get to unique id number 10. When this happens the new variable gives the value of 2, instead of 11 as it should. Someone who understands?

thanks in advance

ksamann

gil davis
11-07-2007, 12:42 PM
Apparently the record returned by your SELECT contains "1" and not "10" as you expect. What is the field type?

ksamann
11-07-2007, 12:53 PM
I did not really think of that one, the field type vas varchar, but changed it to int and the problem was solved. You are a genious man.

thanks a lot!