Hello ,
I create a WP plugin , it is a form that user can submit some data.
lets first look at the code
<?php
include('db.php');
?>
I began my form with :
<?php function form_creation(){?>
<form action=" <?php get_permalink(); ?> " method="post" id="myform">
<table>
<tr>
<td><input type="text" id="txtname" name="txtname" placeholder="Your Name"/> </td>
</tr>
<tr>
<td>
<select id='select_Country' name="select_Country" >
<option selected="selected" disabled="disabled"> -- Select Country -- </option>
<?php
include(db.php);
$query="select Code,Country from _Country order by Country";
$result=mysqli_query($con,$query);
while($row=mysqli_fetch_array($result))
{
echo '<option value='.$row["Code"].'>'.$row["Country"].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td> <input type="submit" id="btnsubmit" value="Submit" name='submit'/> </td>
</tr>
</table>
</form>
<?php }?>
and below is the php code in same page to insert values into DB
<?php
include(db.php);
if($_POST['submit'])
{
$name=strip_tags($_POST['txtname']);
$country=$_POST['select_Country'];
$insertquery="insert into _customers(Name,Country)values('$name',(select Country from _country where Code = '$country')";
$query=mysqli_query($con,$insertquery);
if($query)
{
echo 'Data inserted successfully';
}
else
{
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 .