mysql - Why the following PHP code is not inserting the values in the database? -
I want to include values of a form in the database table named Company. But this program repeatedly tells me that my query has not been executed. I know why this is ??
I have put all the values of the array in the insert and by this I threw the array and gave it name as the new one, so that it can be in a form being put into the database.
But this does not work for me Please tell me what is the problem here?
& lt ;? Php $ host = "localhost"; $ Name = "root"; $ Password = ""; $ Db = "shopping"; $ Con = mysqli_connect ($ host, $ name, $ password, $ db); $ Insert = array (); $ Newarray = array (); If (mysqli_connect_errno ()) {echo ("can not connect to databse". Mysqli_connect_errno ()); Go out(); } And {if ($ _ server ['REQUEST_METHOD'] == 'POST') {foreach ($ _ POST $ value) {if ($ value == $ _POST ['submit']) {break; } And {array_push ($ global ['insert'], $ value); }} $ Newarray = implode (',', $ insert); $ Result = mysqli_query ($ con, "INSERT INTO company (company_name, company_number, company_address) VALUES ($ NewAra)"); If ($ result) {echo ("1 line added"); } And {echo ("unexpected query"); }}}? & Gt;
This line has no value:
Array_push ($ global ['insert'], $ value); Push your values to the one you need $ insert unset ($ _ POST ['submit ']); Forex currency ($ _ POST $ value) {$ insert [] = "'" $ con-> Real_escape_string ($ value). "'"; } $ Newarray = implode (',', $ insert); Note: I suggest suggesting a prepared statement instead.
$ insert = $ con- & gt; Prepare ('INSERT INTO Company (company_name, company_number, company_address)) Price (?,?,?)'); $ Insert-> Bind_param ('sss', $ _POST ['company_name'], $ _POST ['company_number'], $ _POST ['company_address']); $ Insert-> Executed ();
Comments
Post a Comment