0

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

4
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by adam.adamski.96155
0

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.

0

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

0

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

Edited by urtrivedi

1

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)'"

Edited by adam.adamski.96155

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.