2016-03-28 9 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

次のように試してみてください: 'update'はnum_rows' –

+0

があれば、' '使用する必要が戻る文句を言わないのでhttp://www.w3schools.com/php/php_mysql_update.asp (mysqli_affected_rows($ CONN)> 0){' 'if($ stmt-> num_rows> 0){'の代わりに、更新は成功したかどうかに基づいて真または偽を返すので –

答えて

1

UPDATEクエリは、以下のように行う必要があるので、実行が成功に基づいてのみtrueまたはfalseを返すので: -

if(mysqli_affected_rows($conn)>0){代わりのif($stmt->num_rows >0){

OR

if($stmt->execute()){ $stmt->store_result();echo "sucess";header("Location: updategovermentnotification.php");}を使用する必要があります

1

あなたが探しているmysqli_stmtプロパティは$affected_rowsです。これには、INSERT,UPDATEまたはDELETEステートメントの影響を受ける行の数が含まれます。

プロパティ$num_rowsには、SELECTクエリによって返された行数が含まれています。

関連する問題