Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter Kimusubi

    (@kimusubi)

    I sort of solved my own problem. I found two methods of doing it. In the first method, I executed a php code inside the html form and echoed the variable $ulog, like so:

    <input type="hidden" name="user_name" value="<?php echo $ulog; ?>">

    Then I used that in my other php page, ‘DirectBill.php’, and executed the remainder of the code.

    In the second method, I just used $PHP_SELF action in the form and used an if statement to execute the code. This way I kept everything within the editor. It looks a lot neater, but I’m not sure if it’s better or not. This is what the code looks like for the second method:

    <?php
    
    if(isset($_POST['submit']))
    {
    	//Get Current User Login
    	global $current_user;
    	$current_user = wp_get_current_user();
    	$ulog = $current_user->user_login;
    	$tablename_db = "db_".$ulog;
    
    	//Check To See If User Has Already Created Table
    	$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);
    
    	$sql2="INSERT INTO $tablename_db (db_num, db_amnt)
    	VALUES
    	('$_POST[db_num_1]','$_POST[db_amnt_1]')";
    
    	if (!mysql_query($sql2))
    	{
    		die('Error: ' . mysql_error());
    	}
    	echo '<strong>', "Your DBs have been submitted and will be added to your account upon approval.", '</strong>';
    
    }
    ?>
    
    <html>
    <body>
    
    Please fill in your DB information in the form below and press submit. Leave all unused fields blank.
    
    <form method="post" action="<?php echo htmlentities($PHP_SELF); ?>">
    <fieldset>
    <legend>Direct Bill Information:</legend>
    DB #: <input type="int" name="db_num_1" /> DB Amount: <input type="int" name="db_amnt_1" /> </br>
    DB #: <input type="int" name="db_num_2" /> DB Amount: <input type="int" name="db_amnt_2" /> </br>
    DB #: <input type="int" name="db_num_3" /> DB Amount: <input type="int" name="db_amnt_3" /> </br>
    DB #: <input type="int" name="db_num_4" /> DB Amount: <input type="int" name="db_amnt_4" /> </br>
    DB #: <input type="int" name="db_num_5" /> DB Amount: <input type="int" name="db_amnt_5" /> </br>
    DB #: <input type="int" name="db_num_6" /> DB Amount: <input type="int" name="db_amnt_6" /> </br>
    DB #: <input type="int" name="db_num_7" /> DB Amount: <input type="int" name="db_amnt_7" /> </br>
    DB #: <input type="int" name="db_num_8" /> DB Amount: <input type="int" name="db_amnt_8" /> </br>
    DB #: <input type="int" name="db_num_9" /> DB Amount: <input type="int" name="db_amnt_9" /> </br>
    DB #: <input type="int" name="db_num_10" /> DB Amount: <input type="int" name="db_amnt_10" />
    </fieldset>
    <input type="submit" value="submit" name="submit" />
    </form>
    
    </body>
    </html>

    Does anyone know which method is more efficient?

Viewing 1 replies (of 1 total)