Trying to run my first query to INSERT to a database

Discussion in 'Programming' started by mattsaunders, Mar 28, 2007.

  1. #1
    Hey guys im very new to this so be gentle.

    I have created a database for a friend called cyberkitten

    Within the cyberkitten database there is a table called ck_user

    Within the table there are fields called user_id, username, email, password

    I have create a form and I am trying to get the info from the form into the database.


    Here is my code

    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>User Registration</title>
    <link href="../global.css" rel="stylesheet" type="text/css" media="all">
    </head>
    
    <body>
    
    <cfif isDefined('FORM.register_button.y')>
    
    <cfquery datasource="cyberkitten">
    	INSERT into ck_user (username, email, password)
    	VALUES (#FORM.username#', #FORM.email#', #FORM.password#')
    </cfquery>
    <cfelse>
    
    <cfinclude template = "../header.cfm" />
    
    <form action="<cfoutput>#CGI.SCRIPT_NAME#</cfoutput>" method="post">
    
    <br>
    
    <table width="400" border="0" align="center">
      <tr>
        <td><strong>Username</strong></td>
        <td><input type="text" name="username" /></td>
      </tr>
      <tr>
        <td><strong>Email</strong></td>
        <td><input type="text" name="email" /></td>
      </tr>
      <tr>
        <td><strong>Password</strong></td>
        <td><input type="password" name="password" /></td>
      </tr>
      <tr>
        <td><strong>Confirm Password</strong></td>
        <td><input type="password" name="password_confirm" /></td>
      </tr>
      <tr>
        <td><input type="image" name="register_button"  src="../images/register.gif"/></td>
      </tr>
    </table>
    
    
    </form>
    
    </cfif>
    
    </body>
    </html>
    
    Code (markup):

    Thanks in Advance
     
    mattsaunders, Mar 28, 2007 IP
  2. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    This is what you have:

    VALUES (#FORM.username#', #FORM.email#', #FORM.password#')

    This is what you should have

    VALUES ('#FORM.username#', '#FORM.email#', '#FORM.password#')
    You forgot the single quotes.
    Change: <cfif isDefined('FORM.register_button.y')>

    To: <cfif isDefined('FORM.register_button')>


    Everything else looks fine.
     
    datropics, Mar 29, 2007 IP