我试图创建一个插件,可以在我安装的Wordpress上更新mysql上的数据,但是我发现更新不起作用,我可以看到我的管理链接上的表单,而且我也可以访问表单,但当我填写表格并点击Enregistrer我的桌子上没有任何变化时,我确实尝试了很多在互联网上找到的解决方案,但它没有工作。
function test_defaultval() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '"
method="post">';
echo '<p>';
echo 'perdiodecite (requis) <br />';
echo '<input type="text" name="cf-period" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo '<p>';
echo 'ville (requis) <br />';
echo '<input type="text" name="cf-ville" required size="40" />';
echo '</p>';
echo '<p>';
echo 'author (requis) <br />';
echo '<input type="text" name="cf-author" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo 'editor (requis) <br />';
echo '<input type="text" name="cf-editor" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo 'contrubutor (requis) <br />';
echo '<input type="text" name="cf-contrub" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo 'abonne (requis) <br />';
echo '<input type="text" name="cf-abonne" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo '<p><input type="submit" name="cf-submitted"
value="Enregistrer"/></p>';
echo '</form>';
}
function inserer_default() {
// if the submit button is clicked
if ( isset( $_POST['cf-submitted'] ) ) {
// sanitize form values
$periodecite = sanitize_text_field( $_POST["cf-period"] );
$ville = sanitize_text_field( $_POST["cf-ville"] );
$Author = sanitize_text_field( $_POST["cf-author"] );
$Editor = sanitize_text_field( $_POST["cf-editor"] );
$Controbutor = sanitize_text_field( $_POST["cf-contrub"] );
$Abonne = sanitize_text_field( $_POST["cf-abonne"] );
// Code de traitement du formulaire : insertion dans la BD
global $wpdb;
$wpdb->query( $wpdb->prepare("
UPDATE `wwpa_default` SET
defPeriodecite ='".$periodecite."'
defVille ='".$ville."'
defUserAuthor ='".$Author."'
defUserEditor ='".$Editor."'
defUserControbutor ='".$Controbutor."'
defUserAbonne ='".$Abonne."'
WHERE 1
"));
}
}
答案 0 :(得分:0)
您的代码应该是这样,请检查您的更新查询
function test_defaultval() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '"
method="post">';
echo '<p>';
echo 'perdiodecite (requis) <br />';
echo '<input type="text" name="cf-period" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo '<p>';
echo 'ville (requis) <br />';
echo '<input type="text" name="cf-ville" required size="40" />';
echo '</p>';
echo '<p>';
echo 'author (requis) <br />';
echo '<input type="text" name="cf-author" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo 'editor (requis) <br />';
echo '<input type="text" name="cf-editor" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo 'contrubutor (requis) <br />';
echo '<input type="text" name="cf-contrub" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo 'abonne (requis) <br />';
echo '<input type="text" name="cf-abonne" required pattern="[0-1]+"
size="40" />';
echo '</p>';
echo '<p><input type="submit" name="cf-submitted"
value="Enregistrer"/></p>';
echo '</form>';
}
function inserer_default() {
// if the submit button is clicked
if ( isset( $_POST['cf-submitted'] ) ) {
// sanitize form values
$periodecite = sanitize_text_field( $_POST["cf-period"] );
$ville = sanitize_text_field( $_POST["cf-ville"] );
$Author = sanitize_text_field( $_POST["cf-author"] );
$Editor = sanitize_text_field( $_POST["cf-editor"] );
$Controbutor = sanitize_text_field( $_POST["cf-contrub"] );
$Abonne = sanitize_text_field( $_POST["cf-abonne"] );
// Code de traitement du formulaire : insertion dans la BD
global $wpdb;
$wpdb->query(
UPDATE `wwpa_default` SET
defPeriodecite ='".$periodecite."',
defVille ='".$ville."',
defUserAuthor ='".$Author."',
defUserEditor ='".$Editor."',
defUserControbutor ='".$Controbutor."',
defUserAbonne ='".$Abonne."'
WHERE 1);
}
}
希望这会对你有所帮助!!