2017-07-26 13 views
-2
<?php 
    include('dbcon.php'); 
    $code = $_POST['code']; 
    $result=mysqli_query($dbcon,"INSERT into attendance(firstname,lastname,type,year_level,date_added)Select firstname,lastname,type,year_level,CURRENT_TIMESTAMP() FROM member WHERE code='$code'") or die("Error ".mysqli_error()); 
    if(isset($_POST['submit'])) 
    { 
     if(!$result) { 
      echo "Database NOT Found."; 
     } else { 
      $result; 
      header('location:add_member_attendance.php'); 
     } 
    } else {   
    } 
?> 

我想顯示提示符,如果它成功輸入數據並且用戶在數據庫中找不到,但我不知道我的代碼有什麼問題。感謝您幫助我如何提示用戶是否存在於數據庫中

+0

問題?哪裏?有任何錯誤?有什麼不起作用? –

+0

@tny沒有錯誤,但我想提示/顯示用戶已成功進入或數據庫中不存在該用戶 –

回答

0
$query = mysqli_query("INSERT into attendance(firstname,lastname,type,year_level,date_added)Select firstname,lastname,type,year_level,CURRENT_TIMESTAMP() FROM member WHERE code='$code'"); 
$result = ($dbcon,$query); 

$num_rows = mysqli_num_rows($result); 
if(isset($_POST['submit'])){ 

if ($num_rows > 0) { 

    // do something 
} 
else { 
die("Error ".mysqli_error($dbcon)); 
    // do something else 
} 

} 
+0

它正在錄製,但出現錯誤「警告:mysqli_num_rows()期望參數1爲mysqli_result,布爾值在第22行的C:\ wamp64 \ www \ sti_lms \ attendance_save.php中給出「和」警告:mysqli_error()在第30行的C:\ wamp64 \ www \ sti_lms \ attendance_save.php中只給出1個參數,0「錯誤。 –

+0

對不起,它沒有工作,因爲「$ result =($ dbcon,$ query)」中存在錯誤;因此我將其更改爲$ result =($ query);並且在查詢中插入了dbcon,但是之後出現相同的錯誤謝謝你的回覆我的朋友 –

0

你可以試試這個

<?php 
 
include('dbcon.php'); 
 
$code = $_POST['code']; 
 

 

 
if(isset($_POST['submit'])) 
 
{ 
 
$insert=mysqli_query($dbcon,"Select firstname,lastname,type,year_level,CURRENT_TIMESTAMP() FROM member WHERE code='$code'") or die("There was an error checking due to".mysql_error()); 
 

 
if(mysql_num_rows($insert)>0){ 
 
// this means that the code already exist; 
 
$result="INSERT into attendance(firstname,lastname,type,year_level,date_added)Select firstname,lastname,type,year_level,CURRENT_TIMESTAMP() FROM member WHERE code='$code'"; 
 

 
//check if the query run 
 
if(mysqli_query($dbcon,$result)){//or you can do mysql_query($result) 
 
header('location:add_member_attendance.php'); 
 
//you can do anything you want here 
 
}else{ 
 
echo "The insert query did not run due to ".mysql_error(); 
 
} 
 
}else{ 
 

 
echo "The code doesnt exist" 
 
} 
 
} 
 
?>

+0

我把用戶存在或不存在數據庫,但它說「代碼不存在」謝謝你的回覆我的朋友 –

相關問題