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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Not Working cant see why 2

Status
Not open for further replies.

noellees1

Programmer
Feb 2, 2004
383
GB
Hi, ive tried going through this code more than once and still for the life of me cannot get it updating
I get either undefined or syntax error statements

The page codes are as follows

--------user selector-------
Code:
<cfquery name="GetData" datasource="daniel">
	SELECT user_id, user_name
	FROM	tblAdmins
	ORDER BY user_name
</cfquery>

<HTML>
<head>
<title>User Manager</title>
</head>

<body>
<H3> User Profiles</H3>

<table border="3" cellpadding="5" cellspacing="0" bgcolor="#c0c0c0">
<form action="updateform.cfm" method="post">
<TR>
<td rowspan="3">
<select name="user_id" size="5">
<cfoutput query="GetData">
<option value="#user_id#" <cfif GetData.currentRow EQ 1>SELECTED 
</cfif>>#user_name#</OPTION>
</cfoutput>
</select>
</td>
<td><input type="submit" NAME="Update" value="Update Record"></td>
</tr>
<tr>
<td><input type="submit" name="Delete" value="Delete Record"></td></tr>
<td height="39"></tr>
</form>
<tr>
<form action="../new/form.cfm" method="post">
<td>
<input type="submit" name="Insert" value=" Add Record ">&nbsp;</td>
</form>
</tr>
</table>
</centre>
</body>
</HTML>

--------update page --------
Code:
<!--- check to see if we're dealing with a delete operation --->
<CFIF (IsDefined('Form.Delete') AND Trim(Form.Delete) EQ "Delete Record") 
   OR (IsDefined('URL.Action') AND URL.Action EQ "Delete")>
  <CFQUERY NAME="DeleteRecord" DATASOURCE="daniel">
           DELETE FROM tblAdmins
           WHERE user_id = #user_id#
  </CFQUERY>
  <H2>Record Deleted Successfully</H2>
  <!--- abort processing so that the template does not show the update 
        form --->
  <CFABORT>
</CFIF>

<!--- retrieve the record specified by the ID value passed into the
      template by form or url variable --->
<CFQUERY NAME="GetRecord" DATASOURCE="daniel">
         SELECT user_id, user_name, firstname, user_pass, email, permlevel, lastname
         FROM tblAdmins
         WHERE user_id = #user_id#
</CFQUERY>

<HTML>
<HEAD>
    <TITLE>Record Update Form</TITLE>
</HEAD>

<BODY>

<H2>Edit an Existing User</H2>
<FORM ACTION="Update.cfm" METHOD="post">
<!--- include the primary key value for this record so we know which 
      record to update without SQL UPDATE (or CFUPDATE) statement in 
      the next template --->
<CFOUTPUT>
<INPUT TYPE="hidden" NAME="user_id" VALUE="#GetRecord.user_id#">
</CFOUTPUT>

<CFOUTPUT>
<TABLE>
<TR>
  <TD>Username:</TD>
  <TD><INPUT NAME="user_name" TYPE="text" id="user_name" VALUE="#GetRecord.user_name#" 
             SIZE="20" MAXLENGTH="80"></TD>
</TR>
<TR>
  <TD>Password</TD>
  <TD><INPUT NAME="user_pass" TYPE="text" id="user_pass" VALUE="#GetRecord.user_pass#" 
             SIZE="20" MAXLENGTH="80"></TD>
</TR>
<TR>
  <TD>Firstname</TD>
  <TD><INPUT NAME="firstname" TYPE="text" id="firstname" VALUE="#GetRecord.firstname#" 
             SIZE="20" MAXLENGTH="80"></TD>
</TR>
<TR>
  <TD>E-mail:</TD>
  <TD><INPUT TYPE="text" NAME="email" 
             VALUE="#GetRecord.email#" SIZE="20" MAXLENGTH="80"></TD>
</TR>
<TR>
  <TD>Lastname:</TD>
  <TD><INPUT NAME="lastname" TYPE="text" id="lastname" VALUE="#GetRecord.lastname#" 
             SIZE="20" MAXLENGTH="80"></TD>
</TR>
<TR>
  <TD>Permission</TD>
  <TD><INPUT NAME="permlevel" TYPE="text" id="permlevel" VALUE="#GetRecord.permlevel#" 
             SIZE="20" MAXLENGTH="80"></TD>
			 
</TR>
</TABLE>
</CFOUTPUT>

<INPUT TYPE="submit" VALUE="Submit">
</FORM>

</BODY>
</HTML>

-------update processor-------
Code:
<!--- Update the record specified by the ID field.  Note that numeric
      values are not enclosed in single quotes in the SET clause. --->
<CFQUERY NAME="UpdateRecord" DATASOURCE="daniel">
UPDATE tblAdmins
SET user_name = #form.user_name#,
    user_pass = #form.user_pass#, 
    firstname = #form.firstname#, 
    email = #form.email#, 
    lastname = #form.lastname#,
    permlevel = '#form.permlevel#'
WHERE user_id = #form.user_id#    
</CFQUERY>

<!--- retrieve the record we just updated --->
<CFQUERY NAME="GetRecord" DATASOURCE="daniel">
         SELECT user_id, user_name, user_pass, firstname, lastname, email, permlevel
         FROM tblAdmins
         WHERE user_id = #form.user_id#
</CFQUERY>

<HTML>
<HEAD>
    <TITLE>Updated Data</TITLE>
</HEAD>

<BODY>

<H2>Record updated</H2>

<H3>Here are the record details...</H3>

<TABLE CELLPADDING="3" CELLSPACING="0">
<TR BGCOLOR="#888888">
    <TH>UserID</TH>
    <TH>username</TH>
    <TH>password</TH>
    <TH>lastname</TH>
    <TH>E-mail</TH>
    <TH>firstname</TH>
    <TH>permission</TH>
</TR>

<!--- output the record --->
<CFOUTPUT QUERY="GetRecord">
<TR BGCOLOR="##C0C0C0">
    <TD>#user_id#</TD>
    <TD>#user_name#</TD>
    <TD>#user_pass#</TD>
    <TD>#lastname#</TD>
    <TD>#email#</TD>
    <TD>#firstname#</TD>
    <TD>#permlevel#</TD>
</TR>    
</CFOUTPUT>
</TABLE>

</BODY>
</HTML>

Any help most appreciated im sure there must be some stupid error i have made
The DSN is daniel the table is called tblAdmins and the data colums in it are: -
user_name, user_id, user_pass, permlevel, firstname, lastname, email

Cheers for help



The way web design should be
 
please someone help.... i am soo stuck ive been through it again with my pen and still cant see whats wrong.
I removed all the variables apart from user_id and user_pass and still got errors.
I then tried with the whole thing again and got "Syntax error in UPDATE statement."
I cant see anything wrong with it please someone give it a look

The way web design should be
 
The exact errors you're getting would be help full, but a quick glance I came up with this...

<!--- Update the record specified by the ID field. Note that numeric
values are not enclosed in single quotes in the SET clause. --->
<CFQUERY NAME="UpdateRecord" DATASOURCE="daniel">
UPDATE tblAdmins
SET user_name = #form.user_name#,
user_pass = #form.user_pass#,
firstname = #form.firstname#,
email = #form.email#,
lastname = #form.lastname#,
permlevel = '#form.permlevel#'
WHERE user_id = #form.user_id#
</CFQUERY>
looks like all of the values do not have single quotes around them, not just numeric.


Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Sorted it bombboy was right, the ' ' were needed around the fields, i made a mess up
Once that worked it was sorted!
Cheers
Stars for your replys tho

The way web design should be
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top