php - Creating a form to submit data into wordpress database -
I'm trying to come up some ways to get an html form on a WordPress page and it's in the WordPress database Send to Custom Tables I have tried to call the custom php script and write the code in the page and I did not know how to work it. I am trying to understand it, I am about to lose. Where to find a suggestion, enough I'm searching for a week, it would be great.
I have tried to use mysqli_connection, but where do I add that where I add (mysite.com, user, pass, db); And I get another error I can not connect to "user@anotherunknownsite.com" "I have a shared IP, so I wonder if it is connecting to this other site, which has no reference in my code I'm tired of using a local host instead of my site. Nothing works.
This code tries to get some data from the database, but anything B4 where from mysite.com Do not know an error Can be user@randomsite.com and the local host does not work as the only one to connect.
& lt ;? php $ thief = mysqli_connect ("mysite.com", "user", "pass", "db"); // checks connection (mysqli_connect_errno ()) connected to the failed MySQL to {echo ":". mysqli_connect_error ();} $ result = mysqli_query ($ Thieves, "Select from Liquor_Type *"), while echoing ($ line = mysqli_fetch_array ($ result)) {$ line ['lq_name']. " ". $ Line ['description']; echo" & lt;
My form
form action = "setLQType.php "Method =" post "& gt; add a new wine type & lt; / br & gt; & lt; / br & gt; & lt; p & gt; name: & lt; input type =" article "name & Lt; / p & gt; & lt; p & gt; Details & lt; input type = "article" name = "description" /> gt; & lt; / p & gt; ---------------------------------------------- & lt; Input Type = "submit" name = "submit" />
setLQType php file, which is main WordPress The dictionary has got to get it to the file Or, nothing will be done
.php $ thor = mysqli_connect ("mysite.com", "user", "pass", "db_name"); // the Czech connection if (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". mysqli_connect_error ();} $ Name = mysqli_real_escape_string ($ con, $ _POST [ 'name']); $ description = mysqli_real_escape_string ($, $ _POST ['Description']); $ Sql = "Include Lycquery type (lq_name, description) VALUES ('$ name', '$ description)'; If (;! Mysqli_query (die $ con, $ sql) () ( 'Error:'. Mysqli_error ($ con));} "1 Record added" echo; mysqli_close ($ con)? & Gt;
< / Pre>Updated entry page ... setLiquorType.php in website.com/setLiquorType.php
& lt ;? php $ global $ wpdb; $ name = $ _POST [ 'name']; $ description = $ _POST [ 'description']; $ Table_name = $ wpdb- & gt; prefix "Wp_Liquor_Type"; $ Wpdb- & insert gt; ($ table_name, array ( 'lq_name' = & Gt; $ name, 'description' = & gt; $ description)); & gt;
posting works like this:
global $ wpdb; $ Name = sanitize_text_field ($ _POST [ 'name']); $ Lq_name = sanitize_text_field ($ _POST [ 'lq_name']); $ description = $ _POST [ 'description']; $ Table_name = $ wpdb- & gt; prefix "Liquor_Type"; $ Wpdb- & gt; Take ($ Tebl_nam, Array ( 'wine _nam' = & Gt; $ alcohol_name, 'description' = & gt; $ description));
Your mysql connection is available in var $ wpdb
global $ Wpdb; $ Sql = "Select * Type from Alcohol"; $ Line = $ wpdb- & gt; Get_results ($ sql); Forex Currency ($ line as $ data) {echo $ data- & gt; Lq_name "" $ data-> Description; Echo "& lt; br & gt;"; }
Comments
Post a Comment