从另一表单中选择选项

时间:2020-08-07 作者:Arshpreet Venveru

    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>\';
}
我认为现在这是可以理解的。请问有没有人能帮我?

2 个回复
SO网友:shivaramanaiyer

在以下行中:$select_branch = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name"));, 您正在使用$wpdb->prepare不正确。wpdb::prepare 需要两个参数,第一个是带有类似sprintf的占位符的查询字符串,第二个是要替换占位符的值数组。更多详细信息here. 这就是你在你的问题上方所看到的错误。

SO网友:Arshpreet Venveru
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>\';

相关推荐

我在wp_Options表(PhpMyAdmin)中看不到site_url和home_url字段?

我想向你展示这个问题。这是我10年职业生涯中的第一次,过去我曾将许多站点克隆到另一个域,但这是我第一次在Wp\\U选项(phpmyadmin)下看不到“站点URL和主页选项”这是我克隆的域名https://13cabsonline.com.au这是目标域https://silverservice.sydney/我已经通过备份小部件下载并还原了文件。上载文件管理器+数据库,并将数据库与用户连接。但问题是,我无法在phpmyadmin中的Wp\\u options下找到选项。For example: 正常的外