I'm coding a registration form that includes a file upload field. Basically, there are two queries that need to be simultaneously inserted into a database. But unfortunately, I don't know how to do it. So, I need your help.

if ($my_upload->upload()) { // new name is an additional filename information, use this to rename the uploaded file

            query(sprintf("INSERT INTO users SET userimage = '%s'", $my_upload->file_copy));

        }

        }



        // end of file upload part



        if (!empty($_POST["username"]))

        {

            $result = query("INSERT INTO users (firstname, lastname, username, usersex, hash, email) VALUES (?, ?, ?, ?, ?, ?)",

            $_POST["firstname"],

            $_POST["lastname"],

            $_POST["username"],

            $_POST["usersex"],

            crypt($_POST["password"]),

            $_POST["email"]);
        }

Recommended Answers

All 6 Replies

Thanks for replying. query() is a custom function that executes SQL statement, possibly with parameters, returning an array of all rows in result set or false on (non-fatal) error.

I don't see why those two queries should be inserted simultaneously, but either use a transaction, or MySQLi's multi_query.

Sorry, but I don't know how to do InnoDb transactions or MySQLi's multi_query. Can you please, guide me on how to achieve InnoDB transactions? I'd appreciate that.

Thanks for the link. I'm going through the resource to see if I can pull it.

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.