嗨,我的問題是更新數據庫與查詢後,表單中的值將不會更改,即使相同的值(例如team1
),在代碼的底部給了我更新的價值。要更新我必須刷新頁面的表單中的值。更新表單值,更新後在php查詢sql
<form action="" method="post" id="form-partite">
Team Home: <input type="text" name="team1" value="<?php echo $team1 ?>">
Team Away: <input type="text" name="team2" value="<?php echo $team2 ?>">
<input type="submit" name="submit" id="submit">
</form>
<?php
if (isset($_POST['submit'])) {
if ($_POST['team1'] == "" || $_POST['team2'] == ""){
echo "Devi inserire entrambe le squadre";
} else {
$team1 = $_POST['team1'];
$team2 = $_POST['team2'];
$data = array(
'team1' => $team1,
'team2' => $team2
);
global $wpdb;
$wpdb -> update(wp_partite, $data, array(id => '1'));
global $wpdb;
$partita = $wpdb -> get_row("SELECT team1, team2 FROM wp_partite");
$team1 = $partita -> team1;
$team2 = $partita -> team2;
echo "Partita inserita: " . $team1 . " vs " . $team2 . "!";
unset($_POST);
}
}
thanx以獲得有用的解釋! – stockw
歡迎您!如果解決了您的問題,請接受答案。謝謝 –