2014-04-25 40 views
0

我有寫回表格的問題。 我按需要連接到表並正確獲取信息輸出。校正後的輸入和複選框正在保存,因爲我想要。 但我不知道如何寫mysql_fetch_assoc回到表 我有這個kode;將mysql_fetch_assoc中的值插入表單輸入

<?php 
session_start(); 
$_SESSION['mypassword']="myusername"; 
echo "Logged in as:<br>" .$_SESSION['myusername']; 

include "header.inc.php"; 
    include "funksjoner.inc.php"; 
//in this file the connetion to server 

    $connection= kobleTil(); //trenger ikke oppgi databasenavn 

//Steg 2: SQL-query 
$sql = "SELECT * FROM oppgave WHERE modulid=1 AND resultat is NULL ORDER BY RAND() LIMIT 1"; 


$result = mysql_query($sql, $connection); 
echo "<hr>"; 
while ($nextrow= mysql_fetch_assoc($result)){ 
    echo "answer: " . $nextrow['answer']; 
    echo "<br>Modulid: " . $nextrow['modulid']; 
     echo "<br>student: " . $nextrow['studentid']; 
     echo "<br>"; 
} 

echo '<form name="input" action="tilretting.php" method="get">'; 
echo'<input type="text" name="correctedby" value="'.$_SESSION['myusername'].'">'; 
echo 'Not approved<input type="checkbox" name="resultat" value="0">'; 
echo 'Approved<input type="checkbox" name="resultat" value="1">'; 
echo '<input type="text" name="studentid" value="dont know how to write correct here">'; 
echo '<input class="levermodulknapp" type="submit" name="lever1" value="Lever modul 1">'; 
echo "</form>"; 
echo "<hr>"; 
?> 

我怎樣才能得到表單從mysql_fetch_assoc獲取值的形式? mysql_fetch_assoc是否正確使用? 非常gratefull任何提示!

回答

0
$result = mysql_query($sql, $connection); 
echo "<hr>"; 
while ($nextrow= mysql_fetch_assoc($result)){ 
    echo "answer: " . $nextrow['answer']; 
    echo "<br>Modulid: " . $nextrow['modulid']; 
     echo "<br>student: " . $nextrow['studentid']; 
     echo "<br>"; 

echo '<form name="input" action="tilretting.php" method="get">'; 
    echo'<input type="text" name="correctedby" value="'.$_SESSION['myusername'].'">'; 
    echo 'Not approved<input type="checkbox" name="resultat" value="0">'; 
    echo 'Approved<input type="checkbox" name="resultat" value="1">'; 
    echo '<input type="text" name="studentid" value="'.$nextrow['columnName'].'">'; 
    echo '<input class="levermodulknapp" type="submit" name="lever1" value="Lever modul 1">'; 
    echo "</form>"; 
    echo "<hr>"; 
} 

$data = null; 
$result = mysql_query($sql, $connection); 
echo "<hr>"; 
while ($nextrow= mysql_fetch_assoc($result)){ 
    echo "answer: " . $nextrow['answer']; 
    echo "<br>Modulid: " . $nextrow['modulid']; 
     echo "<br>student: " . $nextrow['studentid']; 
     echo "<br>"; 
    $data = $nextrow['colunmName']; 
} 


echo '<form name="input" action="tilretting.php" method="get">'; 
    echo'<input type="text" name="correctedby" value="'.$_SESSION['myusername'].'">'; 
    echo 'Not approved<input type="checkbox" name="resultat" value="0">'; 
    echo 'Approved<input type="checkbox" name="resultat" value="1">'; 
    echo '<input type="text" name="studentid" value="'.$data.'">'; 
    echo '<input class="levermodulknapp" type="submit" name="lever1" value="Lever modul 1">'; 
    echo "</form>"; 
    echo "<hr>"; 
} 
?> 
+0

謝謝你這麼mutcg,神第一個馬上工作,而是我如何調用後值構成形式的行動?一個由我更正了:$ correctedby = $ _POST ['correctedby']; – user2879767

+0

因此您必須將表單方法更改爲發佈。

+0

我這樣做了,但它好像在表格中創建了一個新的roe值。否則它幾乎可以工作。 – user2879767