I know that this is mysqli, but im wondring how to get this query correct. I want to insert username, besvarelse and modulid into table. but if besvarelse is empty or null i want to write back message that its allready delivered.
$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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.