我正在尝试编写一个简单的插件,它可以保存后端表单的输入并选择数据库。在脚本尝试将存储字段值的变量传递给db之前,一切都正常。以下是我的脚本:
ob_start();
$html = ob_get_clean();
if ( isset( $_POST["submit_form"] ) && $_POST["nume"] != "") {
$table = $wpdb->prefix."scoring";
$nume = strip_tags($_POST["nume"], "");
$prenume = strip_tags($_POST["prenume"], "");
$valoarecredit = strip_tags($_POST["valoare-credit-text"], "");
$venit = strip_tags($_POST["venit-text"], "");
$varsta = strip_tags($_POST["varsta-text"], "");
$proprietate = strip_tags($_POST["proprietate-text"], "");
$istoricbc = strip_tags($_POST["istoric-bc-text"], "");
$vechime = strip_tags($_POST["vechime-text"], "");
$perioada = strip_tags($_POST["perioada-text"], "");
$data = array(
\'nume_client\' => $nume,
\'prenume_client\' => $prenume,
\'valoare_credit\' => $valoarecredit,
\'venit\' => $venit,
\'varsta\' => $varsta,
\'proprietate\' => $poprietate,
\'istoric_bc\' => $istoricbc,
\'vechime_loc_de_munca\' => $vechime,
\'perioada_credit\' => $perioada
);
$wpdb->insert( $table, $data, \'%s\' );
echo "<p><strong>" . $table . $wpdb->dbname . Prenume: " . $prenume . "Nume: " . $nume . "Valoare credit: " . $valoarecredit . "Venit: " . $venit . "Varsta: " . $varsta . "Proprietate: " . $proprietate . "Istoric: " . $istoricbc . "Vechime: " . $vechime . "Perioada: " . $perioada . "</strong></p>";
}
// if the form is submitted but the name is empty
else if ( isset( $_POST["submit_form"] ) && $_POST["nume"] == "" )
$html .= "<p>You need to fill the required fields.</p>";
return $html;
如您所见,我试着调试脚本,认为当我得到表名、db或其中一个变量时,可能有问题,但它们的值是正确的。
我反复检查了字段名,认为我不知何故打错了其中一个,但它们都很好。
现在,如果我只是用数据数组中的“1”替换这些变量,脚本就会工作,所有内容都会很好地写入到数据库中(一个全新的数据库记录中充满了1)。
知道我做错了什么吗?
提前感谢!