Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //THIS FUNCTION GRABS CURRENT USER ID
- function get_current_user_id() {
- if ( ! function_exists( 'wp_get_current_user' ) )
- return 0;
- $user = wp_get_current_user();
- return ( isset( $user->ID ) ? (int) $user->ID : 0 );
- }
- // CALL THIS FUNCTION NOW WHILE THE USER IS HERE AND LOGGED IN. THEN THE NEXT PHP PAGE WILL REQUIRE THIS FUNCTION AND INSERT IT INTO THE DB TABLE.
- $wpid = get_current_user_id();
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html lang="en">
- <head>
- <title>CREATE YOUR CHARACTER</title>
- <link href="stylesheets/public.css" media="all"
- rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="header">
- <h1>CREATE YOUR CHARACTER HERE</h1>
- </div>
- <p>Please insert a name for your character.</p><br />
- <form action="form_processor.php" method="post">
- Character Name: <input type="text" name="charname" value"" /><br />
- <br />
- <input type ="submit" name ="submit" value="submit" />
- </form>
- </body>
- </html>
- <?php
- require_once('/home/mythlarp/public_html/wp-content/plugins/character_creation/form.php');
- function redirect_to($new_location) {
- header("Location: " . $new_location);
- }
- //1. CONNECT TO DATABASE
- $dbhost = "localhost";
- $dbuser = "*****";
- $dbpass = "*****";
- $dbname = "*****";
- $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
- //2. GRAB INFORMATION FROM THE FORM IN "form.php" AND ALSO GRAB THE CURRENT WORDPRESS USER'S ID with the variable "$wpid".
- // $charactername = if charactername is set to the form value then use the form value. Otherwise set it to nothing.
- $charname = isset($_POST['charname']) ? $_POST['charname'] : "";
- // This grabs the current Wordpress user ID from "form.php".
- // 3.INSERT FORM VALUES INTO DB TABLE
- $query = "INSERT INTO myth_char_two (";
- $query .= "charname id";
- $query .= ") VALUES (";
- $query .= " '{$charname}', {$wpid}";
- $query .= ")";
- //$result calls the $connection and $query.
- $result = mysqli_query($connection, $query);
- // 4.TEST FOR QUERY ERROR.
- if ($result) {
- redirect_to("character_finish.php");
- } else {
- die("Database query failed.");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement