[PHP-DB] MySQLi Help

2012-06-14 Thread jstarritt

 
Hi,
 
I am trying to slowly convert some old MySQL based code to the newer MySQLi 
extension and have come across something that I want to call a bug, but thought 
maybe as a newb with the extension that this might be something at least a few 
of you are familiar with.  Basically depending on where I call a function from 
I either get errors but there does not seem to be much rhyme or reason too it.  
Here is a very simple code sample -- yes its procedural ...
 
 SUB: $authkv";
 }
 
 mysqli_stmt_close($stmt);
}

function main($db) {

 $authkey = '';

 $sql = "select kv from obj order by kv limit 5";
 $stmt = mysqli_prepare($db, $sql);
 mysqli_stmt_execute($stmt);
 mysqli_stmt_bind_result($stmt, $authkv);

 while (mysqli_stmt_fetch($stmt)) {
 echo "MAIN: $authkv";
 }
 
 sub($db);
 mysqli_stmt_close($stmt);
}

main($db);

?>
 
I get the output I expect:
 
MAIN: 7
MAIN: 8
MAIN: 9
MAIN: 10
MAIN: 11
SUB: 7
SUB: 8
SUB: 9
SUB: 10
SUB: 11
 
This works perfectly however when I call sub from within the while loop in the 
function main this break down. Here is the modification to main:
 
function main($db) {
 
 $authkey = '';
 
 $sql = "select kv from obj order by kv limit 5";
 $stmt = mysqli_prepare($db, $sql);
 mysqli_stmt_execute($stmt);
 mysqli_stmt_bind_result($stmt, $authkv);
 
 while (mysqli_stmt_fetch($stmt)) {
 echo "MAIN: $authkv";
 sub($db);
} 
 
 mysqli_stmt_close($stmt);
 }
 
This simple change results in the output.
 
MAIN: 7
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt,  boolean 
given in /var/www/html/xgwebapi/mysqli.php on line 21  Warning: 
mysqli_stmt_bind_result() expects parameter 1 to be  mysqli_stmt, boolean given 
in /var/www/html/xgwebapi/mysqli.php on line  22  Warning: mysqli_stmt_fetch() 
expects parameter 1 to be mysqli_stmt,  boolean given in 
/var/www/html/xgwebapi/mysqli.php on line 24  Warning: mysqli_stmt_close() 
expects parameter 1 to be mysqli_stmt,  boolean given in 
/var/www/html/xgwebapi/mysqli.php on line 28
 
MAIN: 8
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt,  boolean 
given in /var/www/html/xgwebapi/mysqli.php on line 21  Warning: 
mysqli_stmt_bind_result() expects parameter 1 to be  mysqli_stmt, boolean given 
in /var/www/html/xgwebapi/mysqli.php on line  22  Warning: mysqli_stmt_fetch() 
expects parameter 1 to be mysqli_stmt,  boolean given in 
/var/www/html/xgwebapi/mysqli.php on line 24  Warning: mysqli_stmt_close() 
expects parameter 1 to be mysqli_stmt,  boolean given in 
/var/www/html/xgwebapi/mysqli.php on line 28
 
I do not understand why this would be the case -- clearly.  Does anybody have a 
clue for me?  I am using PHP 5.3.3 on CentOS.  And I am very very very stuck.
 
James

[PHP-DB] Quotation marks in HTML form values

2012-06-14 Thread Ron Piggott

I have setup the following echo after a database query:

\r\n";
?>

What I don’t understand is what to do in the event the variable 
$email_template['description'] retrieved in the database query contains a 
quotation mark “ --- In this event only the word “current” populates the 
“description” field



Ron Piggott



www.TheVerseOfTheDay.info 


Re: [PHP-DB] Quotation marks in HTML form values

2012-06-14 Thread Bastien


Bastien Koert

On 2012-06-15, at 12:35 AM, "Ron Piggott"  
wrote:

> 
> I have setup the following echo after a database query:
> 
>  echo " $email_template['description'] . "\" 
> class=\"contact_center_email_template_maintenance_user_input_data\" />\r\n";
> ?>
> 
> What I don’t understand is what to do in the event the variable 
> $email_template['description'] retrieved in the database query contains a 
> quotation mark “ --- In this event only the word “current” populates the 
> “description” field
> 
>  devotion" e-mail template" 
> class="contact_center_email_template_maintenance_user_input_data" />
> 
> Ron Piggott
> 
> 
> 
> www.TheVerseOfTheDay.info 

Wrap the output in htmlspecialchar()
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Quotation marks in HTML form values

2012-06-14 Thread Karl DeSaulniers


On Jun 14, 2012, at 11:35 PM, Ron Piggott wrote:



I have setup the following echo after a database query:

echo "$email_template['description'] . "\" class= 
\"contact_center_email_template_maintenance_user_input_data\" />\r\n";

?>

What I don’t understand is what to do in the event the variable  
$email_template['description'] retrieved in the database query  
contains a quotation mark “ --- In this event only the word  
“current” populates the “description” field


Day daily devotion" e-mail template"  
class="contact_center_email_template_maintenance_user_input_data" />


Ron Piggott



www.TheVerseOfTheDay.info


Try this

class="contact_center_email_template_maintenance_user_input_data" />


or keep it all inside the echo like you had it.

echo "htmlspecialchars($email_template['description']) . "\" class= 
\"contact_center_email_template_maintenance_user_input_data\" />\r\n";

?>

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Quotation marks in HTML form values

2012-06-14 Thread Karl DeSaulniers


On Jun 14, 2012, at 11:46 PM, Bastien wrote:




Bastien Koert

On 2012-06-15, at 12:35 AM, "Ron Piggott" > wrote:




I have setup the following echo after a database query:

echo "$email_template['description'] . "\" class= 
\"contact_center_email_template_maintenance_user_input_data\" />\r 
\n";

?>

What I don’t understand is what to do in the event the variable  
$email_template['description'] retrieved in the database query  
contains a quotation mark “ --- In this event only the word  
“current” populates the “description” field


Day daily devotion" e-mail template"  
class="contact_center_email_template_maintenance_user_input_data" />


Ron Piggott



www.TheVerseOfTheDay.info


Wrap the output in htmlspecialchar()
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



You Bastien... you beat me to it.. :)


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php