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

时间:2014-05-02 05:12:45

标签: php mysql sql

我在这里做错了什么? (知道它的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>");

    }
?>

2 个答案:

答案 0 :(得分:0)

试试这个并发布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

?>

答案 1 :(得分:0)

尝试检查存在的行,如

$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>");
        }
      }
    }