查询wongt输出到表.正确的语法


query wongt output to table. correct syntax

我做错了什么?(了解其mysql(其他的都不起作用。用户可以多次插入相同的模块id。

$besvarelse = $_GET['besvarelse'];
$modulid = $_GET['modulid'];
$username = $_GET['username'];
$tilkobling = kobleTil(); 
if (!empty($besvarelse) ) {
      $insert = mysql_query("INSERT INTO oppgave (besvarelse, modulid, username) VALUES ('$besvarelse', '$modulid','$username')");

if($insert) {
          echo "<h1>Levering OK</h1><br>";
        }
    }
    else {
        die("<h1>Du har lever før</h1>");
    }
?>

尝试使用此方法并发布PHP显示的错误,请:

//Assuming that connection to mysql server its done somewhere with mysql_connect()
error_reporting(E_ALL); ini_set('display_errors', 1);
explode($_GET);
echo "<pre>";
print_r($_GET); //Just to see what's on the variables...
echo "</pre>;
// $tilkobling = kobleTil(); Need to explain this line
if (!empty($besvarelse) ) {
$sql = "INSERT INTO oppgave (besvarelse, modulid, username) VALUES ('$besvarelse', '$modulid','$username')";
if($insert = mysql_query($sql))
       {
          echo "<h1>Levering OK</h1><br>";
        }
    else {
        die("<h1>Du har lever før</h1>");
    }
} // you were missmatching the IF closing bracket
?>

尝试检查是否存在类似的行

$besvarelse = $_GET['besvarelse'];
$modulid = $_GET['modulid'];
$username = $_GET['username'];
$tilkobling = kobleTil(); 
    if (!empty($besvarelse) ) {
     // check exist moduleid
      $check = mysql_query("select * from oppgave where modulid = '$modulid'");
      $conut_rows= mysql_num_rows($check);
      if($conut_rows > 0) {
        echo "module id already exist";
      }
      else {
        $insert = mysql_query("INSERT INTO oppgave (besvarelse, modulid, username) VALUES ('$besvarelse', '$modulid','$username')");
        if($insert) {
           echo "<h1>Levering OK</h1><br>";
        }
        else {
           die("<h1>Du har lever før</h1>");
        }
      }
    }