Skip to main content
Participating Frequently
April 10, 2011
Question

insert data into mysql through coldfusion

  • April 10, 2011
  • 3 replies
  • 1784 views

hi guys, this code below to insert data into a table in MySQL is correct?

<cfcomponent>

  
    <cffunction name="Register" access="remote" returntype="query">
        <cfargument name="name" required="yes">
        <cfargument name="address" required="yes">
        <cfargument name="fone" required="yes">
        <cfargument name="email" required="yes">
        <cfargument name="username" required="yes">
        <cfargument name="password" required="yes">
   
        <cfquery datasource="Sports_All" name="query_registry">
            INSERT INTO clients(Name, Address, Fone_number, Email, Username, Password)
            VALUES ('#name#', '#address#', '#fone#', '#email#', '#username#', '#password#')
        </cfquery>
       
        <cfreturn query_registry>
       
    </cffunction>
   
</cfcomponent>

Thanks in advance.

    This topic has been closed for replies.

    3 replies

    Known Participant
    April 11, 2011

    Not sure if you have just shortened your code for the example but for a start, don't trust user input - aleast use <cfqueryparam... around your arguments - eg;

    INSERT INTO....

    VALUES ( <cfqueryparam value="#arguments.name#" maxlength="50" cfsqltype="cf_sql_varchar">, ....etc

    You should also specify the "type" in the argument too - eg; type="string".

    What's the problem?

    Inspiring
    April 10, 2011

    What happens when you run it?

    Owainnorth
    Inspiring
    April 10, 2011

    Nope, I can spot two errors right off the bat. When you say "is it correct", what makes you think it's not?