簡體   English   中英

正確的語法查詢插入到表中(MySql)

[英]Correct syntax query insert in to table(MySql)

我知道這是mysqli,但我想知道如何正確獲取此查詢。 我想在表中插入用戶名,besvarelse和modulid。 但是,如果besvarelse為空或null,我想寫回已經准備好傳遞的消息。

$sql  = "INSERT INTO oppgave(username, besvarelse, modulid) 
         select '$username', '$besvarelse', '$modulid'
         from dual
         where not exists (select modulid from oppgave where modulid='$modulid')";

$result=mysql_query($sql, $tilkobling);
if(mysql_affected_rows()==0){
      echo "<h1>Allready delivered</h1>";
}else{
      echo "<h1>Delivery ok</h1>";
}
?>
//«if besvarelse is empty or null i want to write back message that its allready delivered.»
//To check besvarelse we shold not use SQL, it is much better to check it with PHP

if ($besvarelse=='' or is_null($besvarelse)) {
    $resp = "<h1>Allready delivered</h1>";    
} else {
    $sql  = ......;
    $result=mysql_query($sql, $tilkobling);
    if(mysql_affected_rows()==0){
        $resp="<h1>Allready delivered</h1>";
    }else{
        $resp="<h1>Delivery ok</h1>";
}
echo $resp;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM