简体   繁体   中英

how to use database in wordpress for a custom registration form

how to use database in wordpress for a custom registration form.

This is my current code . It returns 404 ERROR.

how to use database in wordpress for a custom registration form.

This is my current code . It returns 404 ERROR.

<?php

$wp_session = WP_Session::get_instance();

 $user_details_array = $wp_session['user_details'];

$reg_id = $user_details_array['regno'];

 $id = $user_details_array['id'];

 if(isset($_POST['submit'])){


  $errors="error";

   $name = $_POST['name'];

  $email =$_POST['email'];

  $mobile =$_POST['mobile'];

  $course=$_POST['course'];

  $regno=$_POST['regNo'] ;

  $sex=$_POST['sex'];



     $con = mysqli_connect("localhost","root","ENrOUTE","inexone");



     $qry  = "INSERT INTO inone_student_details (name,email,mobile,course,regNo,sex,reg_date) VALUES($name,$email,$mobile,$course,$regno,'$sex',NOW())";


          mysqli_query($con, $qry);


 }

  else{
     print_r($errors);
  }





?>

You don't need to connect data using mysql_connect in wordpress, You just use $wpdb global variable get run queries.

global $wpdb;
 $qry  = "INSERT INTO inone_student_details (name,email,mobile,course,regNo,sex,reg_date) VALUES($name,$email,$mobile,$course,$regno,'$sex',NOW())";
$wpdb->query('qry');

For more query reference Wordpress query

wordpress database connection

include '../../../wp-load.php';   (Please specify file path. this file in site root.)
global $wpdb;

wordpress insert query

 $wpdb->query("INSERT INTO inone_student_details (name,email,mobile,course,regNo,sex,reg_date) VALUES('".$name."','".$email."','".$mobile."','".$course."','".$regno."','".$sex."',NOW())");

You have to create page template like in start of you page, then select this template from page template combo box.

Like:

Template Name: Main

See here for adding custom page templates

For data base connectivity, you should use wordpress own global class $wpdb;

Talking to the Database: The wpdb Class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM