Passing PHP Variable Into HTML Form On WordPress Page
-
Let me preface this by saying that I know very little about PHP and HTML. My experience lies with C++. I’m learning all of this as I go, so I appreciate any help that I can get.
I’m executing a PHP code inside my WordPress page (not used as a blog) that basically creates a MySQL table using the user’s login ID, then on the same page I execute an html input form where the user may input some information which is then sent into a separate PHP file, that uses $_POST to insert the information into the MySQL table. The reason I’m doing it this way is because these tables will be deleted on a weekly basis, so they need to be recreated if they do not exist.
The first two steps which are coded inside my WordPress editor (not visual editor) are as follows (I shortened the code here to only pertinent sections):
<?php //Get Current User Login global $current_user; $current_user = wp_get_current_user(); $ulog = $current_user->user_login; $tablename_db = "db_".$ulog; mysql_select_db("data_base_name_here"); //Create Table If It Does Not Exist $sql = "CREATE TABLE IF NOT EXISTS $tablename_db ( ID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(ID), db_num int, db_amnt int );"; mysql_query($sql); ?> <html> <body> <form action="DirectBill.php" method="post"> <fieldset> <legend>Direct Bill Information:</legend> DB #: <input type="int" name="db_num_1" /> DB Amount: <input type="int" name="db_amnt_1" /> </br> <!--Above table entries is repeated 10 more times--> <strong><!--<input type="hidden" name="user_name" value="user_login_ID>--></strong> </fieldset> <input type="submit" /> </form> </body> </html>
The issue that I’m having is that I need to send the user’s login ID as a hidden variable (the comment line that is in bold in the html code) into the ‘DirectBill.php’ page, so that I can use it to process the information, but I can’t seem to figure out how to do that. I also tried including the WordPress API in the ‘DirectBill.php’ page, so that I can just recollect the user ID there, but that didn’t seem to work either.
Does anyone have any suggestions as to how I can accomplish this? Thank you all in advance!
- The topic ‘Passing PHP Variable Into HTML Form On WordPress Page’ is closed to new replies.