2014-06-18 173 views
0

我正在做一个网站,所有者必须能够更新他们的活动,但我的更新代码仍然无法正常工作,即使99%肯定我没有犯过任何错误。MySQL更新不起作用?

首先在按更新形式:

<?php 
$sql = "SELECT * FROM events ORDER BY id ASC"; 

$res = $objCon->query($sql) or die('fejl i query:'.mysqli_error($objCon)); 

while($row=$res->fetch_array()) { 
    $id = $row['id']; 
    echo "<div class='eventpost'>"; 
    echo "<div class='dato'>"; 
    echo $row['id']; 
    echo "</div>"; 
    echo "<p class='overskrift'>"; 
    echo "<a href='update.php?id=$id'>RET </a>"; 
    echo "<a href='code_delete.php?id=$id'>SLET</a>"; 
    echo $row['overskrift']; 
    echo "</p>"; 
    echo "</div>"; 
} 
?> 

则更新形式:

<form action="code_update.php" method="POST"> 
    <label>Dato:<br> 
    <input type="text" name="dag" value="<?php echo $data['dag']; ?>"></label> 
    <label>Månede:<br> 
    <input type="text" name="month" value="<?php echo $data['month']; ?>"></label> 
    <label>Overskrift:<br> 
    <input type="text" name="overskrift" value="<?php echo $data['overskrift']; ?>"></label> 
    <label>Tekst:<br> 
    <input type="text" name="tekst" value="<?php echo $data['tekst']; ?>"></label> 
    <input type="hidden" name="id" value="<? echo $id; ?>"> 
    <input type="submit" value="Opret"> 
</form> 

,最后更新代码

<?php 
session_start(); 
if($_SESSION['auth'] == 2){ 
    include('incl_db.php'); 
    $id = $_POST['id']; 
    $overskrift = $_POST['overskrift']; 
    $dag = $_POST['dag']; 
    $month = $_POST['month']; 
    $tekst = $_POST['tekst']; 
    $sql = "UPDATE events SET overskrift='$overskrift', dag='$dag', month='$month', tekst='$tekst' WHERE id='$id'"; 
    $res = $objCon->query($sql); 

    header('location:events.php'); 
}else{ 
    header('location:index.php'); 
} 
?>   
+0

你有什么错误吗? – Sadikhasan

+0

从'$ id'中删除引号。 – Rikesh

+0

没有错误,删除引号没有做任何事情 – Lampproductions

回答

0

大概速记标签是禁用的PHP版本。所以试着改变这个

<input type="hidden" name="id" value="<? echo $id; ?>"> 

这个

<input type="hidden" name="id" value="<?php echo $id; ?>"> 

您可以check this answer更多。

+0

这样做,因为事实证明我的新服务器不会在<?上注册,谢谢 – Lampproductions

+0

如果没有启用速记标签,它将会有所不同。检查此更多http://stackoverflow.com/questions/2476072/tags-not-working-in-php-5-3-1 –

+0

欢迎@Lampproductions。投票并将答案标记为正确的答案,如果它解决了您的问题。 –