将mysql_fetch_assoc中的值插入表单输入

时间:2014-04-25 09:25:18

标签: php mysql forms input

我有写回桌子的问题。 我按需连接到表并正确输出信息。输入已更正,并且复选框正在保存,因为我想要。  但我不知道如何将mysql_fetch_assoc写回表 我有这个kode;

    <?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是否正确使用? 非常感谢任何提示!

1 个答案:

答案 0 :(得分: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>";
}
?>