Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just Started Coldfusion 1

Status
Not open for further replies.

jasonkeller

Programmer
May 23, 2001
16
US
I currenlty have a working Coldfusion and Access Database web site running for real estate. When a new home is added by the admin, the admin must assign the new home an ID number. Is it possible to have coldfusion/access generate a random ID so the admin can just click on a link that says "ADD NEW" instead of manually assigning and ID
 

Generally this is done by using an auto-number field in your database, then just ignore that field when you insert and the database takes care of it.

But if you must Have a random number you can use

randrange(1,1000) for a random number between 1 and 1000. The problem with doing it this way is that you may end up with multiple Entries with the same ID number. You would have to run a check and it would start to get complicated.

I highly recomend adding an ID field to your database and making it the Primary-Key and set the data type to Autonumber.

If you need help with the insert let me know I'll see what I can do for you.

Have fun...
 
tlhawkins
Thanks...
I don't have to use a random number, it can just be an auto number.

So I have tried several ways to insert my data..still no luck.

Page 1: default.cfm
This page will eventually query for modifing and deleting the database content. Not until I have everything running but for now I just want to click to add. Then go to page 2
<html>
<body>
<a href=&quot;form.cfm&quot;>Add New</a>
</body>
</html>


Page 2: form.cfm
This page is my a testing form for adding info and modifing.
That is basically it. I think I can handle everything else since I have a copy of another site. I can just run through the code to figure the rest out.

<form method=post action=??>
Property Name<input name=&quot;property_name&quot;><br>
Property Address<input name=&quot;property_address&quot;>
<INPUT NAME=&quot;Submit&quot; type=&quot;submit&quot; VALUE=&quot;Submit&quot;>
</form>


Or basically what is the easiest way to do it.

My datasource is &quot;epic.mdb&quot;
and my table is called &quot;property&quot;

 
Hey Jasonkeller,

If you just have the 2 fields:
property_name, property_address

then your input form, the page2 form, looks OK

Page3 should go something like this:

<CFINSERT Datasource=&quot;epic.mdb&quot; tablename=&quot;property&quot;>

That's it. <CFINSERT> will try to insert whatever form variables were just passed to it into the Database. Errors will occur if form variables do not match the fields in the specified table. You wont need to pass the ID field because the database will make that up for you.

You can also use:

<CFINSERT Datasource=&quot;epic.mdb&quot;
Tablename=&quot;property&quot;
FormFields=&quot;property_name,property_address&quot;>

Use this whenever you are passing more form variables then you want to insert.

If you try this and there are any errors Please feel free to post them, I'll take a look again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top