2016-06-08 79 views
0

我有一個配置文件詳細信息的表單,它從我的數據庫中檢索數據,但不更新它。我沒有看到有什麼不對嗎?我試過使用echo來檢查我的代碼是否到達某些地方,但它還沒有工作。表單不更新數據庫

<?php 
session_start(); 

$dbhost = "localhost"; 
$dbuser = "pc4u0fi_username"; 
$dbpass = "pc4upc4u1"; 
$dbname = "pc4u0fi_pc4u"; 

// Create connection 
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname); 
// Check connection 
if ($conn->connect_error) { 
die("Connection failed: " . $conn->connect_error); 
} 

$showalertsuccess = false; 
$showalertdanger = false; 

$retrieve = "SELECT * FROM Klanten WHERE ID = '".$_SESSION['ID']."'"; 
$result = mysqli_query($conn, $retrieve); 
$data = mysqli_fetch_assoc($result); 

$minion = $_GET['ID']; 

if(isset($_POST['submit'])) 
{ 
$voornaam = $_POST['voornaam']; 
$achternaam = $_POST['achternaam']; 
$email = $_POST['email']; 
$username = $_POST['username']; 
$password = $_POST['wachtwoord']; 
$woonplaats = $_POST['woonplaats']; 
$postcode = $_POST['postcode']; 
$straat = $_POST['straat']; 
$huisnr = $_POST['huisnr']; 
$telnr = $_POST['telnr']; 

$query = "UPDATE Klanten SET klant_voornaam='$voornaam', klant_achternaam='$achternaam', klant_email='$email', klant_username='$username', klant_wachtwoord='$password', klant_woonplaats='$woonplaats', klant_postcode='$postcode', klant_straat='$straat', klant_huisnr='$huisnr', klant_telefoonnnummer='$telnr' WHERE ID = '".$_SESSION['ID']."'"; 

if ($conn->query($query) === TRUE) 
{ 
    $showalertsuccess = true; 
} 
else 
{ 
    $showalertdanger = true; 
} 
} 
?> 
<h1 style="margin-left: 10px;">Uw gegevens</h1><br> 
<form class="form-horizontal" role="form" method="post"> 
<div class="alert alert-success fade in" <?php if($showalertsuccess === false) { ?> style="display:none" <?php } ?>> 
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> 
    <strong>Gelukt!</strong> Uw account is gewijzigd. 
</div> 
<div class="alert alert-danger fade in" <?php if($showalertdanger === false) { ?> style="display:none" <?php } ?>> 
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> 
    <strong>Let op!</strong> Er is een fout opgetreden. 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="vnaam">voornaam:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="voornaam" value="<?=$data['klant_voornaam'];?>" name="voornaam" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" for="achternaam" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;">Achternaam:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="achternaam" value="<?=$data['klant_achternaam'];?>" name="achternaam" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="email">Email:</label> 
    <div class="col-sm-10"> 
     <input type="email" class="form-control" id="email" value="<?=$data['klant_email'];?>" name="email" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="username">Username:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="username" value="<?=$data['klant_username'];?>" name="username" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="wachtwoord">Wachtwoord:</label> 
    <div class="col-sm-10"> 
     <input type="password" class="form-control" id="wachtwoord" value="<?=$data['klant_wachtwoord'];?>" name="wachtwoord" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="woonplaats">Woonplaats:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="woonplaats" value="<?=$data['klant_woonplaats'];?>" name="woonplaats" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" for="postcode" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;">Postcode:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="postcode" value="<?=$data['klant_postcode'];?>" name="postcode" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="straat">Straat:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="straat" value="<?=$data['klant_straat'];?>" name="straat" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="huisnr">Huisnummer:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="huisnr" value="<?=$data['klant_huisnr'];?>" name="huisnr" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 20px; margin-top: 10px;" for="telnr">Telefoonnummer:</label> 
    <div class="col-sm-10"> 
     <input type="text" class="form-control" id="telnr" value="<?=$data['klant_telefoonnummer'];?>" name="telnr" style="width: 250px; margin-top: 10px; margin-left: 40px;" required placeholder=""> 
    </div> 
</div> 
<div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-10"> 
     <button type="submit" style="margin-left: 170px; margin-bottom: 20px;" class="btn btn-default" name="submit">Wijzigen</button> 
    </div> 
</div> 
</form> 
+0

呼應查詢並直接運行到phpmyadmin並檢查錯誤! – Saty

+0

你面臨的問題是什麼?你得到的錯誤信息是什麼。錯誤消息是切入點的最佳途徑。 – RanchiRhino

+0

您在$ minion中放置$ _GET ['ID'],然後在where子句中使用$ _SESSION ['ID']。這是一個錯誤還是意圖?還要確保你插入的值沒有任何可能打破查詢的特殊字符('例如) –

回答

-1

如果你使用這個if (isset($_POST['submit'])) { ... }你必須在表單中有<input type="hidden" name="submit" value="ok">

+0

它有提交按鈕,所以不需要拿隱藏字段 – PravinS

+0

哦對不起。然後使用'var_dump($ con> mysql_error());'來檢查錯誤 – Matiratano

0

只要把下面UPDATE部分SELECT查詢,這樣你會得到最後更新的數據

//UPDATE PART 
if(isset($_POST['submit'])) 
{ 
    $voornaam = $_POST['voornaam']; 
    $achternaam = $_POST['achternaam']; 
    $email = $_POST['email']; 
    $username = $_POST['username']; 
    $password = $_POST['wachtwoord']; 
    $woonplaats = $_POST['woonplaats']; 
    $postcode = $_POST['postcode']; 
    $straat = $_POST['straat']; 
    $huisnr = $_POST['huisnr']; 
    $telnr = $_POST['telnr']; 

    $query = "UPDATE Klanten SET klant_voornaam='$voornaam', lant_achternaam='$achternaam', klant_email='$email', klant_username='$username', klant_wachtwoord='$password', klant_woonplaats='$woonplaats', klant_postcode='$postcode', klant_straat='$straat', klant_huisnr='$huisnr', klant_telefoonnnummer='$telnr' WHERE ID = '".$_SESSION['ID']."'"; 

    if ($conn->query($query) === TRUE) 
    { 
    $showalertsuccess = true; 
    } 
    else 
    { 
    $showalertdanger = true; 
    } 
} 


// SELECT QUERY 
$retrieve = "SELECT * FROM Klanten WHERE ID = '".$_SESSION['ID']."'"; 
$result = mysqli_query($conn, $retrieve); 
$data = mysqli_fetch_assoc($result); 
+0

這並不能正常工作。 – Lucafraser

+0

@Lucafraser你是否得到任何錯誤 – PravinS

+0

不,我不是,讓我使用'ini_set('display_startup_errors',1); ini_set('display_errors',1);'第一個 – Lucafraser