php mysql update statment generation from form values -


I am creating a very small database abstract layer, I want to send an array of variables obtained from a form, and an update SQL statements generate, and ultimately execute it. For example

  $ table name = "user" What do I put on the second row from the row given below? $ Username = $ _post ['username']; $ Password = $ _post ['password']; $ Email = $ _post ['email']; $ Array = (user name = & gt; $ user name, password = & gt; $ password, email = & gt; $ email); $ Query = "Update $ this-> TableName" $ ​​value = "form value" from the assc array as database value; $ query = "WHERE status";  

You can use a foreach () loop to generate your query Note your array that you need to declare your array with the array () , and quote your co-workers.

  // ... $ Array = array ('username' = & gt; $ username, 'passer D = = & gt; $ password, 'email' = & gt; $ email); $ Query = "update". $ This-> TableName. "SET"; Foreign Exchange ($ Array $ field = & gt; $ Value) {$ query. = "` "$ Field." `= '". Mysql_real_escape_string ($ value). "', '; } // kick off of travel comma $ query = substr ($ query, 0, -1); $ Query = "WHERE status";  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -