Hi
I am inserting in database but there is error in query. i have array in which form data is stored and function recieve the array but data is not inserting in array. bellow is the code.

$insArr=array();
        $insArr['first_name']=addslashes($_REQUEST['first_name']);
        $insArr['last_name']=addslashes($_REQUEST['last_name']);
        $insArr['email']=addslashes($_REQUEST['emailid']);
        etc there is 46 fields in table

        //now the function that insert in table is below

        function mf_dbinsert($table,$data)  // FUNCTION TO INSERT NEW RECORD IN SPECIFIED TABLE
        {
            $qry="INSERT INTO ".$table." values ";
            foreach($data as $fld=>$val)
            {
                $qry.= $fld."='".$this->add_security($val)."',";
            }
            $qry=substr($qry,0,-1);

            return $this->mf_query($qry);
        }

solve this problem waiting for your reply
Thanks

Recommended Answers

All 5 Replies

what error u getting?
eroor message or record not inserting?

Where are you calling the function mf_dbinsert?

Seeing as you're not explicitly listing the table columns, are you inserting a value for every field? If not, that is the likely cause of your error.

Either explicitly list the column names, or ensure a value for every field, including the ID (pass as NULL) is provided.

It says that record inserted but actually record is not inserted in database

i think its missing parenthesis () around value list
inset do not work with = sign, what u doing is for update query.

I believe we have two insert types with MySQL:
"INSERT INTO tablename set field='value', column='amount'...", and
"INSERT INTO tablename (field, column) VALUES ('value', 'amount')"
But your query is a mixture of both and neither:
"INSERT INTO ".$table." values $fld='$this->add_security($val)'"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.