2016-03-28 35 views
1

在此代碼中,我使用了準備好的語句查詢,我想要行數但在下面的代碼中它返回零行。請告訴我我的代碼中有什麼問題。以下代碼總是將行數回退爲零總是

$servername = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname="lamp"; 
$conn = new mysqli($servername,$username,$password,$dbname); 
if ($conn->connect_error) 
{ 
    die("Connection failed: " . $conn->connect_error); 
} 
$contactno=mysqli_real_escape_string($conn,$_POST['contactno']); 
$description=mysqli_real_escape_string($conn,$_POST['description']); 
$email=mysqli_real_escape_string($conn,$_POST['contactemail']); 

$subject=mysqli_real_escape_string($conn,$_POST['subject']); 
$creationdate=mysqli_real_escape_string($conn,$_POST['creationdate']); 
if(isset($_POST['status1'])) 
{ 
    $status =$_POST['status1']; 
} 
if(isset($_POST['noteid'])) 
{ 
    $id = mysqli_real_escape_string($conn,$_POST['noteid']); 
} 
$stmt=$conn->prepare("update notifications set subject=?,description=? 
,status=?, creationdate=?,contactno=?,contactemail=? where id=? ");    $stmt->bind_param("ssisisi",$subject,$description,$status,$creationdate,$contactno,$email,$id); 
$stmt->execute(); 
$stmt->store_result(); 
if($stmt->num_rows >0) 
{ 
    echo "sucess"; 
    header("Location: updategovermentnotification.php"); 
} 
+0

嘗試這樣的:http://www.w3schools.com/php/php_mysql_update.asp 因爲'update'不會返回'num_rows' –

+0

需要使用'如果(mysqli_affected_rows($康恩)> 0){'而不是'if($ stmt-> num_rows> 0){'因爲更新只會根據成功執行返回true或false –

回答

1

由於UPDATE查詢返回truefalse基於成功執行,那麼你需要做的象下面這樣: -

需要使用if(mysqli_affected_rows($conn)>0){代替if($stmt->num_rows >0){

OR

if($stmt->execute()){ $stmt->store_result();echo "sucess";header("Location: updategovermentnotification.php");}