Jump to content

prepared statement fail in php8


guymclarenza
Go to solution Solved by kicken,

Recommended Posts

$sqli= $pdo->query("SELECT * FROM pages WHERE page_website='".$site."' ORDER by page_id ASC LIMIT 0,1");
	while ($rowi = $sqli->fetch())
		{ 
		$bid=$rowi["page_id"];
	      $img=$rowi["page_img"];
	      $imga=$rowi["page_imgalt"];
	      $title=$rowi["page_title"];
	      $pge=$rowi["page_text"];
	      $pint=$rowi["page_intro"];
	      $ptop=$rowi["page_banner"];
	      $pvid=$rowi["page_video"];
	      $tags=$rowi["page_tags"];
	      $metadesc=$rowi["page_desc"];
	      $ontology=$rowi["page_onto"];
	      $ontodesc=$rowi["page_ontodesc"];
		}

Gives me this as a result on page. In my limited understanding  it would seem that pdo->query no longer gives the desired results in php8. This works in php7. I seem to be too stupid to find why this is.  Can anyone point me in the right direction please. 

Quote

 

query("SELECT * FROM pages WHERE page_id='42' ORDER by page_id ASC LIMIT 0,1"); while ($rowi = $sqli->fetch()) { $bid=$rowi["page_id"]; $img=$rowi["page_img"]; $imga=$rowi["page_imgalt"]; $title=$rowi["page_title"]; $pge=$rowi["page_text"]; $pint=$rowi["page_intro"]; $ptop=$rowi["page_banner"]; $pvid=$rowi["page_video"]; $tags=$rowi["page_tags"]; $metadesc=$rowi["page_desc"]; $ontology=$rowi["page_onto"]; $ontodesc=$rowi["page_ontodesc"]; } include ("navigation/heada.php"); echo "

"; echo ""; echo nl2br($pge); echo "

"; echo "

"; include ("navigation/lnav.php"); ?>

 

 

Link to comment
Share on other sites

I don't see the "this" you refer to.  How many records were returned?

And please don't post code that is simply a flowing block of text.  Very hard to read and make sense of.  And if that is how you are writing your code I strongly suggest you change your style.

And what is it you expect to see?

And this is not using any prepared statements.

Edited by ginerjm
Link to comment
Share on other sites

  • Solution
2 hours ago, guymclarenza said:

Gives me this as a result on page

If you're seeing the source code to your page displayed when you load it, then this is not some problem with prepared queries but a problem of your code not being parsed at all.  This would either be due to PHP not being installed and configured correctly, or you using short tags and your PHP installation no longer being configured to allow them.

 

Link to comment
Share on other sites

Thanks to everyone that tried to help, I have been busy with my real job. Making wooden stuff. 

I found the solution and my site now works under php8.1, hopefully I never need to do this again unless I feel like making a change. 

If you want to see the site it's at DustFactory 

<? wasn't doing it, I had to make all instances <?php

 

Edited by guymclarenza
Link to comment
Share on other sites

Yes - <?php has been the norm for awhile now - just didn't cause a failure until recently.  It has been the suggested format for some time.  Glad you found it.

Below is a (perhaps?) cleaner version of your code.  Something that makes it a bit clearer (to me at least):

// Always specify the column names you want to select, not just a *.
// IMHO - define the query in a string var so that you can easily show it if necessary without having to re-type it. Perhaps you may 
// want to add it to an error output to see what it looks like during debugging.
//
$q = "SELECT page_id, page_img, page_imgalt, page_title, page_text, page_intro, page_baanner, page_video, 
			page_tags, page_desc, page_onto, page_ontodesc 
		FROM pages 
		WHERE page_website = '$site' 
		ORDER by page_id 
		LIMIT 0,1";
if (!$qst = $pdo->query($q))
{
	echo "Error - query did not run";	//add error message output here too.
	exit();
}
//  process the results now
	while (list($id, $img, $imga, $title, $text, $int, $banner, $vid, $tags, $desc, $ontology, $ontodesc) = $qst->fetch(PDO::FETCH_NUM))
	{ 
		// do your output work here with the vars (slightly modified) provided in the list()
		...
		...
	}

Next step is to learn to use prepared queries, especially when inserting user-provided values in a query.

 

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.