Add/Delete/Modify Database Record form

This is a discussion on "Add/Delete/Modify Database Record form" within the Starting Out section. This forum, and the thread "Add/Delete/Modify Database Record form are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Starting Out

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 21st, 2007, 12:02
Junior Member
Join Date: Nov 2005
Location: Wisconsin
Age: 38
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Add/Delete/Modify Database Record form

I have a form set up in which I want the viewer to be able to select a job title from a list menu. From that selection, I want them to have the option to modify or delete that job selection or add a new job. WIth that I have a "Edit Posting" button, "Delete Posting" or "Add New Posting" button in the form for them to submit the form with. But how do I set it up so each button will submit to the appropriate page, (i.e the modify the selected job page, the delete the selected job page, or the create new job page"

Here is the code I have set up. I am using Coldfusion:

<cfquery name="JobPost"
datasource="kpstool_accesscf_jobs">
SELECT * FROM jobs
</cfquery>
<p class="Photos">Please select an option below:</p>
<form action="UticaUpdateJob.cfm" method="post">
<table width="310" border="1">
<tr>
<td width="120" class="Copy">Job Position: </td>
<td colspan="2"><select name="Title" id="Position" class="formcopy">
<option value="Jobs">Choose One</option>
<cfoutput query="JobPost">
<option value="#JobID#">#Title#</option>
</cfoutput>
</select></td>
</tr>
<tr>
<td><input name="submit" type="submit" id="submit" value="Edit Posting"></td>
<td width="62"><input type="submit" id="Delete Posting" value="Modify Posting"></td>
<td width="106"><input name="submit2" type="submit" id="submit2" value="Insert New Posting"></td>
</tr>
</table>
</form>

Thanks,
Dave
Reply With Quote

  #2 (permalink)  
Old Apr 23rd, 2007, 11:03
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Add/Delete/Modify Database Record form

One option would be to place a hidden field in your form.

Attach an event handler to your submit buttons so that JavaScript places a value in the hidden field coresponding to the button pressed.

Your action page can now identify which button was pressed by looking at the value of that hidden and redirect accordingly.
Reply With Quote
  #3 (permalink)  
Old Apr 30th, 2007, 17:47
Junior Member
Join Date: Nov 2005
Location: Wisconsin
Age: 38
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Add/Delete/Modify Database Record form

This is the code I have now set up which functions except for one thing. When the user selects the "New Posting" option, I want it to get the insert template. However, currently I have to have a value selected for "Model" in order for it to go to the insert page which obviously doesn't make sense as the button should redirect to the insert template whether a value was selected or not. Basically, if the insert option is selected, I want the page to stop processing and redirect to the insert template. Any ideas as to how I need to revise my code?

<cfoutput>
<cfif isdefined("form.Insert")>
<cfinclude template="../Admincopy/UticaInsertPosting.cfm">
</cfif>
<cfif form.Model is "Model">
<cflocation url="UticaJobPostings.cfm?Message=Please select a Model to edit">
<cfexit>
</cfif>
<cfif IsDefined("form.edit")>
<cfinclude template="../Admincopy/UticaEditJob.cfm">
<cfelseif isdefined("form.Delete")>
<cfinclude template="../Admincopy/UticaDeleteJob.cfm">
</cfif>
</cfoutput>
Reply With Quote
  #4 (permalink)  
Old Apr 30th, 2007, 20:09
Junior Member
Join Date: Nov 2005
Location: Wisconsin
Age: 38
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Add/Delete/Modify Database Record form

Never mind- I got it- just threw a cfexit after the include template for the insert posting!

Dave
Reply With Quote
  #5 (permalink)  
Old May 1st, 2007, 14:15
Junior Member
Join Date: Nov 2005
Location: Wisconsin
Age: 38
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Add/Delete/Modify Database Record form

I seem to have a new problem with my update form page. It seems I am getting a syntax error in my UPDATE statement.

Here is the error message:

Error Executing Database Query.

Syntax error in UPDATE statement.

The error occurred in D:\Hosting\uticarenew\Admincopy\UticaUpdatedJobInf o.cfm: line 92
90 : Date = '#Form.Date#',
91 : Active = '#Form.Active#'
92 : WHERE AutoID = #Form.AutoID#
93 : </cfquery>
94 : <cfoutput>
SQL UPDATE Gas SET Model = 'Chevy', MPG = 20, Date = '1-10-01', Active = 'Yes' WHERE AutoID = 2
DATASOURCE UticaRenew_accesscf_Mileage
VENDORERRORCODE 3092
SQLSTATE &nbsp;

As you can see, it is pulling in the AutoID as being "2". I don't have quotes around the #form.AutoID# so I can't see what the syntax error is. Any ideas??

Dave
Reply With Quote
  #6 (permalink)  
Old May 1st, 2007, 15:00
Junior Member
Join Date: Nov 2005
Location: Wisconsin
Age: 38
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Add/Delete/Modify Database Record form

Well I figured "Date" was a reserved word and changed it, but still get the same issue:

Syntax error in UPDATE statement.

The error occurred in D:\Hosting\uticarenew\Admincopy\UticaUpdatedJobInf o.cfm: line 92
90 : Date = '#Form.Calendar#',
91 : Active = '#Form.Active#'
92 : WHERE AutoID = #Form.AutoID#
93 : </cfquery>
94 : <cfoutput>
SQL UPDATE Gas SET Model = 'Blake', MPG = 20, Date = '1/11/01', Active = 'Yes' WHERE AutoID = 6
DATASOURCE UticaRenew_accesscf_Mileage
VENDORERRORCODE 3092
SQLSTATE &nbsp;

Also, the Date or "Calendar" field as it is labeled in the database, is a text field, hense the quotes. Active is a checkbox with a "Yes" value

Dave
Reply With Quote
  #7 (permalink)  
Old May 1st, 2007, 16:22
Junior Member
Join Date: Nov 2005
Location: Wisconsin
Age: 38
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Add/Delete/Modify Database Record form

I figured it out! Forgot to change Date to Calendar in my code. But here's a new problem.

In my submission form, I have a checkbox that I want the user to check if that posting should be active or, come up as a listing when it does a query to display the current listings. (hope that makes sense). I set the checkbox value to be "Yes"
I noticed however that my form will come back with an undefined error for that checkbox if it is not checked. How would I need to revise my code for either the form page or the cfm action page for that form for it to simply not insert a yes value in the database field "Active" for that listing?

Basically, on the display page for the listings, I will have it query only the listings with a "yes" value in the Active field.

Here is a snipit of the code for the checkbox form itself. It is the code for my update listing.

<td><input type="text" name="Calendar" value="#Calendar#"></td>
<tr>
<td><input name="Active" type="checkbox" id="Active" value="Yes"></td>

<input type="hidden" name="AutoID" value="#AutoID#">

Here is the cfm insert page code for this:

<cfquery name="JobPost"
datasource= "UticaRenew_accesscf_Mileage">
UPDATE Gas
SET Model = '#Form.Model#',
MPG = #Form.MPG#,
Calendar = '#Form.Calendar#',
Active = '#Form.Active#'
WHERE AutoID = #Form.AutoID#
</cfquery>

Dave
Reply With Quote
Reply

Tags
coldfusion

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting a record from a database Colm Osiris Databases 2 Feb 13th, 2006 21:43
display first only part of a database record. Daddyohhh99 Other Programming Languages 0 Feb 3rd, 2006 14:49
Delete record problem Gee Bee Databases 2 Jan 4th, 2006 18:28
Delete All Record in a search result page? Monie Classic ASP 3 Nov 11th, 2004 03:27
display the number of record exist in the database Monie Databases 1 Aug 24th, 2004 08:10


All times are GMT. The time now is 05:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43