SQL INSERT INTO statement to add a record (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


mylu -> SQL INSERT INTO statement to add a record (3/31/2007 0:07:50)

I need to add a record to one table and update one column in a second table.

I have a form that post to ASP script. User inputs data to form. Clicks submit. Form post to ASP script to ADD a record to table one:

INSERT INTO tbl_tickets_data (ticket_number,resolution,error_code,updated_by) VALUES ('ticket_number','resolution','error_code','updated_by')

this will of course add the values ticket_number, resolution, error_code, updated_by to the columns of 'ticket_number','resolution','error_code','updated_by' in the table tbl_tickets_data.

What I need is for the VALUES in the form to be dynamic for what ever the user adds to those fields.

The SQL statement above is static and I can't figure out how to make the new record to the table dynamic to what ever the user inputs from the form.

Thanks.




Spooky -> RE: SQL INSERT INTO statement to add a record (3/31/2007 4:30:34)

Can you just expand on "What I need is for the VALUES in the form to be dynamic for what ever the user adds to those fields. " ?




mylu -> RE: SQL INSERT INTO statement to add a record (3/31/2007 20:16:05)

Why yes I can!

With the SQL statement:

INSERT INTO tbl_tickets_data (ticket_number,resolution,error_code,updated_by) VALUES ('ticket_number','resolution','error_code','updated_by')

The Values added to the record are ticket_number, resolution, error_code , updated_by. Literally. When you click submit the words ticket_number, resolution, error_code , updated_by are added to the columns ticket_number, resolution, error_code , updated_by in the table tbl_tickets_data. (which is what the statement woould do as written)

ticket_number is a field on my form. The field is auto populated by passing the "actual" ticket number, say 28445, from the actual record 28445 in the tbl_tickets table to the form. From there I need to pass that ticket number to the SQL statement above. So the data added to the table tbl_tickets_data.ticket_number needs to be dynamic. The ticket_number is the key field in the relational database. IE table one contains the original ticket and table two contains additional notes to the ticket with ticket_number and the primary key.

Make sense?




Spooky -> RE: SQL INSERT INTO statement to add a record (3/31/2007 22:25:22)

Assuming thats part of an asp / SQL statement, you would need to do something like this?

sql = "INSERT INTO tbl_tickets_data (ticket_number,resolution,error_code,updated_by) VALUES ('"&request.form("ticket_number")&"','resolution','error_code','updated_by')"


Is that what you were meaning?
Thats the bare minimum for form submission, and you would be best to sanitize the input if used on the internet




mylu -> RE: SQL INSERT INTO statement to add a record (3/31/2007 22:34:57)

The SQL statement is the input on a DRW. I may be going about this the worng way I don't know.

"Thats the bare minimum for form submission, and you would be best to sanitize the input if used on the internet"

Can you explain this statement if you don't mind?

Thanks




Spooky -> RE: SQL INSERT INTO statement to add a record (4/1/2007 0:04:27)

For a DRW, this should be all you need (if entered as custom SQL in the wizard):

INSERT INTO tbl_tickets_data (ticket_number,resolution,error_code,updated_by) VALUES ('::ticket_number::','::resolution::','::error_code::','::updated_by::')




mylu -> RE: SQL INSERT INTO statement to add a record (4/1/2007 10:17:35)

I must be getting better at this because I tried that same code. All I get is an error "the custom query contains errors"When verify the query. And it doesn't pop up the error box describing the error.

The results are
Database Results Wizard Error
Unable to find operator in query string. Query string currently is INSERT INTO tbl_tickets_data (ticket_number,resolution,error_code,updated_by) VALUES ('::ticket_number::','::resolution::','::error_code::','::updated_by::')
One or more form fields were empty. You should provide default values for all form fields that are used in the query.

All fields do contain data..




Spooky -> RE: SQL INSERT INTO statement to add a record (4/1/2007 14:07:13)

As with ticket_number, are the other form fields named the same as the actual form text box?
Are there other columns in this database? Do they allow null or zero length inputs?




mylu -> RE: SQL INSERT INTO statement to add a record (4/1/2007 23:31:46)

Thanks for the conversation.. You pointed me in the correct direction:
Here's the statement that works.

fp_sQry="INSERT INTO tbl_tickets_data (ticket_number,resolution,error_code,updated_by,Timestamp,cpanel_name) VALUES ('"&request.form("ticket_number")&"','"&request.form("resolution")&"','"&request.form("error_code")&"','"&request.form("updated_by")&"','"&request.form("Timestamp")&"','"&request.form("cpanel_name")&"')"

Could you please explain your comment "you would be best to sanitize the input if used on the internet" ???

Thanks again..




Spooky -> RE: SQL INSERT INTO statement to add a record (4/2/2007 2:23:32)

An example :
http://www.frontpagewebmaster.com/m-352053/tm.htm




mylu -> RE: SQL INSERT INTO statement to add a record (4/2/2007 10:37:03)

Thanks! Since we're using FP DRW I guess I can assume we're OK.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875