PHP - Shall I Use Mysqli_stmt_free_result($stmt) Or Not ?
Php Whizzs! Here is my login.php partial relevant to the case code: $query_1 = "SELECT id,recruits_number,sponsor_username,account_activation_status,id_video_verification_status,id_verification_video_file_url,username,password,primary_domain,primary_website_email,registering_country,registering_ip,registering_browser,registering_os,registering_isp,age_range FROM users WHERE $querying_column = ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'s',$login_username_or_email_or_domain); mysqli_stmt_execute($stmt_1); //Check if User's details was successfully extracted or not from 'users' tbl. if (!$stmt_1) { echo "ERROR 1: Sorry! Our system is currently experiencing a problem logging you in!"; exit(); } else { $result_1 = mysqli_stmt_bind_result($stmt_1,$db_id,$db_recruits_number,$db_sponsor_username,$db_account_activation_status,$db_id_video_verification_status,$db_id_verification_video_file_url,$db_username,$db_password,$db_primary_domain,$db_website_email,$db_registering_country,$registering_ip,$registering_browser,$registering_os,$registering_isp,$db_age_range); mysqli_stmt_fetch($stmt_1); mysqli_stmt_close($stmt_1); //Free Result_1 Set mysqli_stmt_free_result($stmt_1);
I can login to user account with accurate password. Good! With wrong password, supposed to get error: "Incorrect log-in details". Instead get this:
"Warning: mysqli_stmt_free_result(): Couldn't fetch mysqli_stmt in C:\xampp\htdocs\test\login_v1.php on line 58 Line 58 is the last one: $result_1 = mysqli_stmt_bind_result($stmt_1,$db_id,$db_recruits_number,$db_sponsor_username,$db_account_activation_status,$db_id_video_verification_status,$db_id_verification_video_file_url,$db_username,$db_password,$db_primary_domain,$db_website_email,$db_registering_country,$registering_ip,$registering_browser,$registering_os,$registering_isp,$db_age_range); mysqli_stmt_fetch($stmt_1); mysqli_stmt_close($stmt_1); //Free Result_1 Set mysqli_stmt_free_result($stmt_1);
I read that you use "mysqli_stmt_free_result($stmt)" if you use mysqli_stmt_store_result($stmt). Is this causing the error ? Should I remove mysqli_stmt_free_result($stmt) ? Or, instead of this: mysqli_stmt_close($stmt_1); //Free Result_1 Set mysqli_stmt_free_result($stmt_1);
Should I do this: //Free Result_1 Set mysqli_stmt_free_result($stmt_1); mysqli_stmt_close($stmt_1);
Or, maybe I should add another line ? If so, then what and where ? Already checked the manual and stuck! How-about a sample code from your end ? Edited November 28, 2018 by phpsaneSimilar TutorialsHello ,
I am trying to update a record in my table if the particular value exists in the rows of a table. But my if-else not working properly. I am not getting where i am going wrong.
here is my table authorization, where i define authorization % with min and max.
authorisation.JPG 16.83KB
0 downloads
after adding line items, before display i will check whether any one of the line item discount lies within this min and max and also checks whether authorization is required (required='Yes'/'No') for that discount in my authorization table. If authorization required then i will update that order number as authorized.
here is my line items table
line_items.JPG 20.37KB
0 downloads
I am doing like this
while($row=mysql_fetch_array($query)) { $dis1 = "SELECT auth_id, auth_min, auth_max, required FROM sales_authorisation"; $dis2 = mysql_query($dis1) or die (mysql_error()); while($d1 = mysql_fetch_array($dis2)) { $min = $d1['auth_min']; $max = $d1['auth_max']; $req = $d1['required']; //echo $req; if( ($min <= ($row['discount'])) && ($max >= ($row['discount'])) && ($req='Yes')) { $auth = "UPDATE orders SET authorise='No' WHERE order_id=".$order_id.""; echo "hello"; } else { $auth = "UPDATE orders SET authorise='Yes' WHERE order_id=".$order_id.""; } $auth1 = mysql_query($auth) or die (mysql_error()); } ?> <tr> <td><?php echo $counter++; ?></td> <td><?php echo $row['itemname']; ?> - <?php echo $row['uom']; ?></td> <td><?php echo $row['description']; ?></td> <td><?php echo $row['quantity']; ?></td> <td><?php echo number_format($row['selling_price'],2); ?></td> <td><?php echo $row['discount']; ?> %</td> <td><?php echo $row['tname']; ?>-<?php echo $row['rate']; ?> %</td> <td><?php echo $row['freight']; ?></td> <td><?php echo number_format($row['total'],2); ?></td> </tr>While loop is for displaying line items for the order. But my if condition doesn't works . Not getting how to do it. please suggest Hi,
I have two scripts using almost identical code. Is this because PHP 7 needs to use only indexes in the WHERE part of SQL Query? Here are the two scripts - first one works $sql = 'SELECT access,fname FROM clients WHERE email=?'; $stmt = $connect->prepare($sql); $stmt->execute([$email]); $data_exists = ($stmt->fetchColumn() > 0) ? true : false; if ($data_exists) { // account found. $row = $stmt->fetch(); $access = $row['access']; $fname = $row['fname']; } else { $err_msg = 'Invalid Email Address and/or Password.'; $email = ''; $pass = ''; require_once ("login_fm.php"); exit; } [/PHP]
$sql = 'SELECT email,fname,lname,confirm FROM clients WHERE user_key=?'; $stmt = $connect->prepare($sql); $stmt->execute([$the_key]); $data_exists = ($stmt->fetchColumn() > 0) ? true : false; if ($data_exists) { // Account found. $row = $stmt->fetch(); $email = $row['email']; $name = $row['fname'].' '.$row['lname']; $confirm = $row['confirm']; $_SESSION['auth'] = "yes"; $_SESSION['email'] = $email; $_SESSION['name'] = $name; $sql = 'UPDATE clients SET confirm = ?,log_count = log_count+1,last_date=? WHERE email=?'; $stmt= $connect->prepare($sql); $stmt->execute(['y',$today_time,$email]); require_once("index.php"); // SUCCESSFUL LOGIN: THIS LOADS THE START PAGE exit; } // end if else { $err_page_message = "ERROR - Account not found $the_key : $name"; require_once("err.php"); exit; } // end else
May be it's a different reason - like I'm too tied !
But it would be nice to know why it isn't working.
It's quite simple, I just want to check to see if a row exists with the condition given, that's all. I never had this problem the old mysql but the PDO seems a bit tricky or I'm just using the wrong code lol.
Thanks Edited June 15, 2019 by David-LondonCode: [Select] $params = array(); $type=array(); $fragments = array(); while (list($chiave,$val) = each($_POST)){ if($val!=""){ $fragments[] = $chiave." = ?"; //echo $chiave; if($chiave=="ritiro" or $chiave=="data") $params[] = normalToDbDate($val); else $params[] = $val; if($chiave=="legale") $type[]='i'; else $type[]='s'; } } $prova=implode("",$type); foreach($params as $param) echo "<p>".$param."</p>"; //echo "val(".count($params).")-->".implode(',',$params); //echo "type(".strlen($prova).")-->".implode("",$type); $sql = $db->prepare("..... AND ".implode(" AND ", $fragments)); array_unshift($params,$prova) call_user_func_array( array( $sql, 'bind_param' ),$params); //$sql->bind_param($prova,$params); $sql->execute(); hi all, with the tructure above i've tried to implement the cration of a dynamic query for a search form. i debugged with echoes and che numbers of bind_param and the those in the prepared statement match in sense that count($params)=strlen($prova). having said that i get this error: Code: [Select] Warning: call_user_func_array() expects parameter 2 to be array, integer given in and no results are shown to me even when the filter match. Hi all !
I have a piece of code he
$result = display_all(fcon, $var1, $var2); function display_all( // defined in another file $query = "SELECT one, two, three four, index1, index2 FROM numbers WHERE index1 = $var1 LIMIT 0, 1"; $result = mysqli_query($fcon, $query); return ($result); )and then I use the returned variable $result to display the value as follows:- while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>".$one."</td>"; echo "<td>".$two."</td>"; echo "<td>".$three. "</td>"; echo "<td>".$four. "</td>"; echo "<td>".$index1. "</td>"; echo "</tr>"; }and this displays the n rows of data returned. Now I have started using prepared statements and the function is now function display_all{ $query = "SELECT one, two, three four, index1 FROM numbers WHERE index1 = ? LIMIT 0, 10"; $stmt = $conn->prepare($query); $stmt->bind_param('i',$var) if($stmt->execute()) { $stmt->bind_result($one, $two, $three, $four, $index1); $stmt->store_result(); } return($stmt); }However the returned $stmt object is unable to display the n rows of data since it shows null values. I assume that this is not the right way to use the $stmt object to display data. I must be missing something. So I request you guys to help me with this. Thanks loads. Edited by ajoo, 23 December 2014 - 11:24 AM. |