[英]how to use database in wordpress for a custom registration form
如何在wordpress中使用数据库创建自定义注册表格。
这是我当前的代码。 它返回404错误。
如何在wordpress中使用数据库创建自定义注册表格。
这是我当前的代码。 它返回404错误。
<?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);
}
?>
您无需在wordpress中使用mysql_connect连接数据,只需使用$ wpdb全局变量get run查询即可。
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');
有关更多查询,请参考Wordpress查询
wordpress数据库连接
include '../../../wp-load.php'; (Please specify file path. this file in site root.)
global $wpdb;
WordPress的插入查询
$wpdb->query("INSERT INTO inone_student_details (name,email,mobile,course,regNo,sex,reg_date) VALUES('".$name."','".$email."','".$mobile."','".$course."','".$regno."','".$sex."',NOW())");
您必须像在页面开始时一样创建页面模板,然后从页面模板组合框中选择此模板。
喜欢:
Template Name: Main
请参阅此处以添加自定义页面模板
对于数据库连接,您应该使用wordpress自己的全局类$wpdb;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.