php - Foreach variable to update databse wordpress -
How can a database be given to update the database?
If instead of one variable, I give numbers, okay, I think this is a mistake.
global $ wpdb; $ Wpdb- & gt; Teams = $ wpdb-> Prefix 'Thames'; $ Retrieve_data = $ wpdb- & gt; Get_results ("SELECT * FROM $ wpdb- & gt; teams where middle = 'ni' '); Foreign exchange ($ retrieve_data $ as recovery_data) {echo "form method = 'post' 'gt; & lt; table & gt; & lt; tr & gt;"; Echo "& lt; td & gt;" $ Recovered- datas-> Id. "& Lt; / td>"; Input type = 'hidden' name = 'id' & gt; "$ Recovered." And "input id". & Lt; / Input & gt; Input = 'Submit' value = 'OK' /> & Lt; / Td> "; Echo" & lt; / Tr & gt; & Lt; / Table & gt; & Lt; / Form & gt; ";} $ Id = $ _POST ['id']; set type ($ id, 'int'); $ wpdb- & gt; update ('team', array ('medium' = & gt; ; 'Tak'), array ('id' = & gt; $ id));
Whatever you are doing is basically wrong.You can show the form, then you can update your table at no cost.After submitting the form, update the table. But if any page Loading, and do not submit the form, you will re-update it to 0.
I think, you Id field will also need to be validated.
Try this way:
global $ wpdb; $ Wpdb- & gt; teams = $ wpdb-> gt; Also, prefix 'teams' also do this before any output in the buffer ... // check is $ $ _POST ["id"]. And move this update block to the top of your file if (isset ( $ {Id = $ _POST ['id']; set type ($ id, 'int'); $ wpdb- & gt; update ('team', array ('medium' = & Gt; 'tak'), array ('id' = & gt; $ id)) // redirects the user to any type of top (" Location: ". $ _SERVER ["PHP_SELF"]); } $ Retrieve_data = $ wpdb- & gt; Get_results ("SELECT * FROM $ wpdb-> Teams where medium = 'NiA'"); Foreign exchange ($ retrieve_data $ as recovery_data) {echo "form method = 'post' 'gt; & lt; table & gt; & lt; tr & gt;"; Echo "& lt; td & gt;" . $ Recovered- datas-> ID "& lt; / td & gt;"; Echo "& lt; td & gt;" . $ Recovered- datas-> Nazwa "& lt; input type = 'hidden' name = 'id' & gt;" . $ Recovered- datas-> Id "& lt; / input & gt; & lt; input type = 'submit' value = 'OK' /> & lt; / td & gt;"; Echo "& lt; / tr & gt; "; }
Comments
Post a Comment