doulu2011 2018-05-13 00:14
浏览 40
已采纳

我的PHP表单没有发送数据到phpmyadmin

i am trying to build a wordpress plugin that will allow the admin to create user from the admin page after creating the form and the process php code, i refresed my wordpress but no error but then after filling the form and click on the register button it is showing me page not found and the i have placed the classifiedbr.php and demo.php on the same folder but it is still not working

this is my php code named classfiedbr.php

<?php
/**
* @package ClassifiedBr
*/
/*
Plugin Name: ClassifiedBr
Plugin URI: http://britchi.com/plugin
Description: This is my first Attempt on writting a custom plugin
Version: 1.0.0
Author: *Bright* C Godwin 
Author URI: http://britchi.com/plugin
License: GPLv2 or later
Text Domain: classifiedbr-plugin
*/
add_action('admin_menu', 'classifiedbr_setup_menu');


function classifiedbr_setup_menu(){
        add_menu_page( 'ClassifiedBr Page', 'ClassifiedBr', 'manage_options', 'classifiedbr', 'classifiedbr_init' );
}

function classifiedbr_init(){
    echo '<form action="demo.php" method="post" />';
    echo "<h1>Britchi Tracking</h1>";
    echo '<p>';
    echo 'Costumers Name (required) <br/>';
    echo '<input type="text" name="cname"/>';
    echo '</p>';
    echo '<p>';
    echo 'Tracking number (required) <br/>';
    echo '<input type="text" name="ctracking"/>';
    echo '</p>';
    echo '<p>';
    echo 'Email (required) <br/>';
    echo '<input type="email" name="cemail" />';
    echo '</p>';
    echo '<p>';
    echo 'Recived Port (required) <br/>';
    echo '<input type="text" name="crport" />';
    echo '</p>';
    echo '<p>';
    echo 'Delivered Port (required) <br/>';
    echo '<input type="text" name="cdport" />';
    echo '</p>';
    echo '<p>';
    echo 'Current Location (required) <br/>';
    echo '<input type="text" name="clocation" />';
    echo '</p>';
    echo '<p>';
    echo 'Destination (required) <br/>';
    echo '<input type="text" name="cdestination". />';
    echo '</p>';
    echo '<p><input type="submit" name="cregistered" value="Register"></p>';
    echo '</form>';




}

?>

then this is my demo.php

<?php

define('DB_NAME', 'class');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_selected_db(DB_NAME, $link);

if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}

$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ctracking = $_POST['ctracking'];
$crport = $_POST['crport'];
$cdport = $_POST['cdport'];
$cname = $_POST['clocation'];
$cname = $_POST['cdestination'];

$sql = "INSERT INTO demo (cname, cemail, ctracking, erport, cdport, clocation, cdestination) VALUES ('$cname', 'cemail', 'ctracking', 'crport', 'cdport', 'clocation', 'cdestination')";

if (!mysql_query($sql)) {
    die('ERROR: ' . mysql_error());
}

mysql_close();
?>

this is the page

enter image description here

this is the error massage i get from the page

enter image description here

this is the folder where i saved the files

enter image description here

i have tried searching here but the question that is related to my own problem (my php form not insert to phpmyadmin) but it is not yet solved so i am hoping someone can help me out thanks

  • 写回答

1条回答 默认 最新

  • dongmaoxi0477 2018-05-13 16:08
    关注

    Just make the below changes in your demo.php and put both the files in wp-admin of Wordpress directory.

    <?php
    
    define('DB_NAME', 'class');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_HOST', 'localhost');
    
    $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    
    
    
    if (!$link) {
        die('Can\'t use ' . DB_NAME . ': ' . mysqli_error($link));
    }
    
       $cname = $_POST['cname'];
       $cemail = $_POST['cemail'];
       $ctracking = $_POST['ctracking'];
       $crport = $_POST['crport'];
       $cdport = $_POST['cdport'];
       $clocation = $_POST['clocation'];
       $cdestination = $_POST['cdestination'];
    
       $sql = "INSERT INTO demo (cname, cemail, ctracking, crport, cdport,  clocation, cdestination) VALUES ('$cname', '$cemail', '$ctracking', '$crport', '$cdport', '$clocation', '$cdestination')";
    
    if (!mysqli_query($link, $sql)) {
        die('ERROR: ' . mysqli_error($link));
    
    }
    
       mysqli_close($link);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计