Jump to content
Larry Ullman's Book Forums

From Single Prepared Stmt, One Value Is Printed, Other Not (In Live Stage)


Recommended Posts

I am trying to update my scripts using prepared statements. (Till now I was exercising regular queries.)

 

My updated scripts work very well on local host, but gives hard times on live site. (I have created a live site just to know and practice how things work.)

The following code prints only title of the article, while article content is not displayed. I tried to check different print statements, checking column names number of times and checking syntex of binding result set. But still not come up with the reason.

(I have changed table and column names here. The live site is www.myreadinglog.net. This script is first two links on left bar.)

 

 

if((isset($_GET['gg'])) && (is_numeric($_GET['gg'])))

{ //from a.php

$a = (int)$_GET['gg']; //Typecast gg.

 

}

else { //No valid Id, kill the script.

echo '<p> This page has been accessed in erro.</p>';

include('includes/newf.html');

exit();

}

//Make a prepared statement query to select content for the given article ID:

$q = "SELECT qt, qon FROM comma WHERE a = ? LIMIT 1";

 

 

//Prepare the statment, assigning result to a variable:

if($stmt = mysqli_prepare($dbc, $q))

{

 

//bind variable to query's placeholder:

mysqli_stmt_bind_param($stmt,'i', $a);

 

//Execute the statement:

mysqli_stmt_execute($stmt);

 

//Bind result variables:

mysqli_stmt_bind_result($stmt, $title, $content);

 

//store result:

mysqli_stmt_store_result($stmt);

 

if(mysqli_stmt_num_rows($stmt) > 0)

{

//if statement execution returns any row, then

//fetch value and display:

while(mysqli_stmt_fetch($stmt))

{

echo "<big><b>$title</b></big>\n"; //This value is printed correctly.

//echo nl2br($content);

printf("%s\n", nl2br($content)); //But this value is not being printed.

}

}

else {

echo "There is no content here.";

}

//close statment:

mysqli_stmt_close($stmt);

} //End of IF($stmt).

Link to comment
Share on other sites

Thanks for reply. I am using mysqli_stmt_bind_result as already shown in my code. And it displays $title value, but not displaying $content value. May be this is some kind of display problem. I am still getting mad about this.. -_- May be I need to use something different than "%s " in printf function. But why then echo is not working as well? How can I print error from prepared statements in this condition?

Link to comment
Share on other sites

Sorry about that. Had to catch a train, and I must have overlooked that you used it.

 

- A suggestion. Have you tried to run the query using something like phpmyadmin?

- echo mysqli_stmt_errno($stmt) will give you any error messages or the string "zero" if none.

 

Looked at your site. I can see both title and content on the links described. Did you solve this?

  • Upvote 1
Link to comment
Share on other sites

Hi Antonio, thanks again for suggestions. (I have not yet solved the problem. The content on the site is displayed using old, simple query script.)

 

mysqli_stmt_errono and mysqli_stmt_error are not showing any errors, because query is running properly. It shows title atleast. I also run the query multiple times in phpmyadmin through my hosting plan. It shows result correctly there. That's why it has been difficult to know the cause of problem.

 

Anyway, thanks a lot for giving time to see all these things.

Link to comment
Share on other sites

 Share

×
×
  • Create New...