Click here to Skip to main content
14,095,911 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello ,
I create a WP plugin , it is a form that user can submit some data.
lets first look at the code
Plugin Name: My Plugin
Description: test plugin
Version: 4.0
Author: Hercal
License: GPL
include('db.php'); //database connection file located in same folder .

I began my form with :
<?php function form_creation(){?>
<form action=" <?php get_permalink(); ?> " method="post" id="myform">

<td><input type="text" id="txtname" name="txtname" placeholder="Your Name"/> </td>

<select id='select_Country' name="select_Country" >
		<option selected="selected" disabled="disabled"> -- Select Country -- </option>
        $query="select Code,Country from _Country order by Country";
            echo '<option value='.$row["Code"].'>'.$row["Country"].'</option>';

<td>  <input type="submit" id="btnsubmit" value="Submit" name='submit'/> </td>
<?php }?>

and below is the php code in same page to insert values into DB
$insertquery="insert into _customers(Name,Country)values('$name',(select Country from _country where Code = '$country')";
		echo 'Data inserted successfully';
		echo 'there is a problem<br/>';
		print_r( (mysqli_errno($con)));

and finally below line also in same page to create a short code for this form
<?php add_shortcode('test', 'form_creation');?>

Now , when i use (test) shortcode and put it on my wordpress page , form loaded ,displayed but there is one problem .

1-Country field didn't load from database , so the drop down load with only one choice
,Select Country

keep in mind :
1-when I Enter a name and press submit , name inserted successfully to DB which means that db.php has no problem , so why the select country query didn't return values.

2-when i run the same code on root(without WP) , it works fine and country loaded successfully but when i call this plugin from WordPress using ShortCode , problem happens

I need your support , thanks .
Robinvb 11-Dec-14 19:34pm
I had this same kind of problem a while ago, only to figure out Wordpress doesn't send an array back from the database, it handles it like objects, so I needed to use;


If this isn't what you mean, I'm very sorry!
I'll try and look into my own code tomorow if this doesn't help you at all :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190518.1 | Last Updated 9 Dec 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100