user5549553
user5549553

Reputation:

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);
  }





?>

Upvotes: 0

Views: 154

Answers (3)

Muhammad Muazzam
Muhammad Muazzam

Reputation: 2800

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

Upvotes: 0

Manish Jesani
Manish Jesani

Reputation: 1357

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())");

Upvotes: 0

Vishal Kamal
Vishal Kamal

Reputation: 1124

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

Upvotes: 1

Related Questions