Advertisement
Guest User

Untitled

a guest
Aug 21st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <?php
  2. //THIS FUNCTION GRABS CURRENT USER ID
  3. function get_current_user_id() {
  4. if ( ! function_exists( 'wp_get_current_user' ) )
  5. return 0;
  6. $user = wp_get_current_user();
  7. return ( isset( $user->ID ) ? (int) $user->ID : 0 );
  8. }
  9. // 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.
  10. $wpid = get_current_user_id();
  11. ?>
  12.  
  13.  
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  15. "http://www.w3.org/TR/html4/loose.dtd">
  16.  
  17. <html lang="en">
  18. <head>
  19. <title>CREATE YOUR CHARACTER</title>
  20. <link href="stylesheets/public.css" media="all"
  21. rel="stylesheet" type="text/css" />
  22. </head>
  23. <body>
  24. <div id="header">
  25. <h1>CREATE YOUR CHARACTER HERE</h1>
  26. </div>
  27. <p>Please insert a name for your character.</p><br />
  28.  
  29. <form action="form_processor.php" method="post">
  30. Character Name: <input type="text" name="charname" value"" /><br />
  31. <br />
  32. <input type ="submit" name ="submit" value="submit" />
  33. </form>
  34. </body>
  35. </html>
  36.  
  37. <?php
  38.  
  39. require_once('/home/mythlarp/public_html/wp-content/plugins/character_creation/form.php');
  40.  
  41. function redirect_to($new_location) {
  42. header("Location: " . $new_location);
  43. }
  44.  
  45.  
  46. //1. CONNECT TO DATABASE
  47. $dbhost = "localhost";
  48. $dbuser = "*****";
  49. $dbpass = "*****";
  50. $dbname = "*****";
  51. $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  52.  
  53. //2. GRAB INFORMATION FROM THE FORM IN "form.php" AND ALSO GRAB THE CURRENT WORDPRESS USER'S ID with the variable "$wpid".
  54.  
  55. // $charactername = if charactername is set to the form value then use the form value. Otherwise set it to nothing.
  56.  
  57. $charname = isset($_POST['charname']) ? $_POST['charname'] : "";
  58. // This grabs the current Wordpress user ID from "form.php".
  59.  
  60.  
  61. // 3.INSERT FORM VALUES INTO DB TABLE
  62. $query = "INSERT INTO myth_char_two (";
  63. $query .= "charname id";
  64. $query .= ") VALUES (";
  65. $query .= " '{$charname}', {$wpid}";
  66. $query .= ")";
  67. //$result calls the $connection and $query.
  68. $result = mysqli_query($connection, $query);
  69. // 4.TEST FOR QUERY ERROR.
  70. if ($result) {
  71. redirect_to("character_finish.php");
  72. } else {
  73. die("Database query failed.");
  74. }
  75.  
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement