在HTML表单提交后重新加载MYSQL中的值

时间:2014-02-25 19:53:39

标签: php mysql submission

我有通过PHP与MYSQL数据库链接的HTML表单。如果我提交此表单,则值将保存在MYSQL数据库中,但不会加载到表单中。我看到旧的值,所以我必须刷新页面才能看到所需的值。

我希望在表单提交时看到新值。

<?php
ob_start();
session_start();

?>
<div id="submenu"><div class="selected-settings"><a href="edit.php?page=zakladni_udaje.php" style="text-decoration: none">Základní údaje</a></div> | <a href="edit.php?page=osobni_rekordy.php" style="text-decoration: none">Osobní rekordy</a> | <a href="edit.php?page=zmena_hesla.php" style="text-decoration: none">Změna hesla</a></div>
<br><br><br>

<form action="edit.php?page=zakladni_udaje.php" method="post">
<?php

$con = mysql_connect("localhost", "mairichovci", "ak41801") or die("Nelze se připojit k MySQL: " . mysql_error());              
mysql_select_db("mairichovci") or die("Nelze vybrat databázi: ". mysql_error());

if($_SESSION['id'] > 0){

$profil_pomocny = mysql_query("SELECT * from profil where id=".$_SESSION['id'], $con);
$profil = MySQL_Fetch_Assoc($profil_pomocny);

$or_pomocny = mysql_query("SELECT * from osobaky where id=".$_SESSION['id'], $con);
$or = MySQL_Fetch_Assoc($or_pomocny);

$zobraz_pomocny = mysql_query("SELECT * from zobraz where id=".$_SESSION['id'], $con);
$zobraz = MySQL_Fetch_Assoc($zobraz_pomocny);


$id = $_SESSION['id'];
$fce = $_POST['fce'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$position = $_POST['position'];
$home = $_POST['home'];
$omne = $_POST['omne'];




if( isset ($_POST['uloz'])):



$sql = "UPDATE profil SET
fce = '$fce', email = '$email', tel = $tel, position = '$position', home = '$home', omne = '$omne' WHERE id = '$id'";

if (!mysql_query($sql)):
  die('Chyba: ' . mysql_error());
else: 
$message = "Údaje byly uloženy";
endif;



mysql_close();


endif;
echo '<div id="message">'.$message.'</div>';
?>



<table style = "margin-top: -1px" align="center" class="tabulka">
    <tr>
        <td width="40%">Funkce:</td>
        <td><input type="text" name="fce" placeholder = "(např. Běžec - 800m, 1500m a delší)" maxlength="35" size="48" value="<?php echo $profil['fce']; ?>" class="vstupy" style="width: 350px"></td>
    </tr>
    <tr>
        <td>E-mail a telefon:</td>
        <td><input type="text" name="email" maxlength="40" size="30" placeholder="E-mail" value="<?php echo $profil['email']; ?>" class="vstupy" style="width: 245px"><input type="text" placeholder="Telefon" name="tel" maxlength="9" size="8" value="<?php echo $profil['tel']; ?>" class="vstupy" style="width: 102px"></td>
    </tr>
    <tr>
        <td>Pozice (škola/zaměstnání):</td>
        <td><input type="text" name="position" placeholder="(např. Student - Gymnázium Teplice)" maxlength="70" size="45" value="<?php echo $profil['position']; ?>" class="vstupy" style="width: 350px"></td>
    </tr>
    <tr>
        <td>Bydliště</td>
        <td><input type="text" name="home" placeholder="Ulice + číslo popisné, Město + PSČ" maxlength="50" size="45" value="<?php echo $profil['home']; ?>" class="vstupy" style="width: 350px"></td>
    </tr>
    <tr>
        <td>O mně:</td>
        <td><textarea name="omne" placeholder="Napiš něco o sobě a svojí kariéře" maxlength="800" rows="4" class="vstupy" style="width: 350px; height: auto"><?php echo $profil['omne']; ?></textarea></td>
    </tr>
  <tr>
  <td></td>
  <td><input type="submit" name="uloz" value="Ulož" class="tlacitko2" style="width: 350px; margin-left:4px"></td>
  </tr>



</table> 
</form>




<?php


}
else{header("Location: prihlas.php");}
ob_end_flush();
?>

任何人都可以帮助我吗? 提前谢谢。

0 个答案:

没有答案