简体   繁体   English

正确的语法查询插入到表中(MySql)

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

I know that this is mysqli, but im wondring how to get this query correct. 我知道这是mysqli,但我想知道如何正确获取此查询。 I want to insert username, besvarelse and modulid into table. 我想在表中插入用户名,besvarelse和modulid。 but if besvarelse is empty or null i want to write back message that its allready delivered. 但是,如果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