最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - selecting options from another form

programmeradmin2浏览0评论
    Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.0.) in /home/****/public_html/wp-includes/functions.php on line 5167
    
    Notice: Undefined offset: 0 in /home/****/public_html/wp-includes/wp-db.php on line 1310
function branch_students(){
       $content='';
$content.='<div class="container">';
$content.='<h1 align=center class="fofa">Enter Branch</h1>';
$content.='<form method="post" >';
$content.='<div class="b2">';
$content.='<input type="text" name="branch" id="branch" class="box" placeholder="Enter Branch" required */></div>';
$content.='<br>';
$content.='<div>';
$content.='<button type="submit" name="save" class="btn_Register" value="save">Save</button>';
$content.='</div>';
$content.='</form>';
$content.='</div>';
return $content;
}
this is my first form in this form i creates branches. now i want database of this branch form should be showed in the following table as selection options.
function arsh_forms(){
$content .='<div class="col-sm-6">';
$content .='<label class="fofa"  style=" font: italic bold 12px/30px Georgia, serif; font-size:26px;color:black;">Select Branch</label>';
  $content .='<select  name="selectbranch"id="selectbranch"  class="form-control"style=" font: italic bold 12px/30px Georgia, serif; font-size:20px;"placeholder="selectbranch"required/>';
    $content .='<option value="0" >select branch</option>';
    global $wpdb;
    $table_name=$wpdb->prefix.'arsh_branch';
    $select_branch = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name"));
    if(count($select_branch) > 0){
        foreach ($select_branch as $key=>$value){
          
            $content .='<option value="<?php echo $value->branches; ?>">
                <?php echo ucwords($value->branches);?></option>';
            
        }
        
    }
    
          $content .='</select>';
$content.='<div class="col-sm-6">';
$content .='<button type="submit" name="submit" value="Register" style=" width:30%;height:35px;background-color:black;color:white;float:right; margin-top:40px;" 
class="bt">Register</button>';
      $content .='</div>';
}

i think now it is understandable.plz if anybody can help me?

    Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.0.) in /home/****/public_html/wp-includes/functions.php on line 5167
    
    Notice: Undefined offset: 0 in /home/****/public_html/wp-includes/wp-db.php on line 1310
function branch_students(){
       $content='';
$content.='<div class="container">';
$content.='<h1 align=center class="fofa">Enter Branch</h1>';
$content.='<form method="post" >';
$content.='<div class="b2">';
$content.='<input type="text" name="branch" id="branch" class="box" placeholder="Enter Branch" required */></div>';
$content.='<br>';
$content.='<div>';
$content.='<button type="submit" name="save" class="btn_Register" value="save">Save</button>';
$content.='</div>';
$content.='</form>';
$content.='</div>';
return $content;
}
this is my first form in this form i creates branches. now i want database of this branch form should be showed in the following table as selection options.
function arsh_forms(){
$content .='<div class="col-sm-6">';
$content .='<label class="fofa"  style=" font: italic bold 12px/30px Georgia, serif; font-size:26px;color:black;">Select Branch</label>';
  $content .='<select  name="selectbranch"id="selectbranch"  class="form-control"style=" font: italic bold 12px/30px Georgia, serif; font-size:20px;"placeholder="selectbranch"required/>';
    $content .='<option value="0" >select branch</option>';
    global $wpdb;
    $table_name=$wpdb->prefix.'arsh_branch';
    $select_branch = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name"));
    if(count($select_branch) > 0){
        foreach ($select_branch as $key=>$value){
          
            $content .='<option value="<?php echo $value->branches; ?>">
                <?php echo ucwords($value->branches);?></option>';
            
        }
        
    }
    
          $content .='</select>';
$content.='<div class="col-sm-6">';
$content .='<button type="submit" name="submit" value="Register" style=" width:30%;height:35px;background-color:black;color:white;float:right; margin-top:40px;" 
class="bt">Register</button>';
      $content .='</div>';
}

i think now it is understandable.plz if anybody can help me?

Share Improve this question edited Aug 7, 2020 at 9:42 Arshpreet Venveru asked Aug 7, 2020 at 6:16 Arshpreet VenveruArshpreet Venveru 94 bronze badges 4
  • What's your question? – Jacob Peattie Commented Aug 7, 2020 at 6:43
  • i want to add select option in my form and i added items in other form but it should showed on this form as selecting items. – Arshpreet Venveru Commented Aug 7, 2020 at 6:47
  • Nothing included in the question is remotely useful in understanding your issue (what's the other form? how is it saved?), and I can't see what it has to do with WordPress either. – Jacob Peattie Commented Aug 7, 2020 at 6:58
  • Although I have given an answer on what I believe is incorrect in your code. I do agree with Jacob, that, the question should be clearly written here with more details to allow people to answer. You can still edit the question and update it so that if someone else stumbles here, they can get a better understanding of it as well – shivaramanaiyer Commented Aug 7, 2020 at 7:29
Add a comment  | 

2 Answers 2

Reset to default 0

In the following line: $select_branch = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name"));, you are using $wpdb->prepareincorrectly. wpdb::prepare needs two arguments, first one is a Query string with sprintf like placeholders and second an array of the values to to substitute the placeholders. More details here. And that is the error you are getting as posted on top of your question.

yeah i got answer 
$content .='<select  name="selectbranch"id="selectbranch"  class="form-control"style=" font: italic bold 12px/30px Georgia, serif; font-size:20px;"placeholder="selectbranch"required/>';
$content .='<option >select branch</option>';
global $wpdb;
$table_name=$wpdb->prefix.'arsh_branch';
$select_branch = $wpdb->get_results("SELECT * FROM $table_name");

if(count($select_branch) > 0){
    foreach ($select_branch as $key=>$value){
        
        $content .='<option value= "'.$value->branches.'">'
            .$value->branches.'</option>';
       
    }
    
}


      $content .='</select>';
发布评论

评论列表(0)

  1. 暂无评论