Script returns nothing

Hello,

I recently updated to php 7.0 and one of my scripts that was previously working fine, now no longer works. At first the problem was obsolete code, which I have sense corrected.

However, now the script simply doesn’t actually return anything how it is suppose to.

The point of this script is to automatically pull content from a post elsewhere on my forums and post it in a reply to a new topic created after a form is submitted. The Automation works perfectly until I look at the post and see that it is blank I can’t figure out how to get the content to actually show even though the following code looks like it should be working

[php]// This works by pulling up the content of the first post of the topic you designate by ID number.
// To find a topic’s ID, look at the topic’s URL, it’s a five or six digit number
// Replace the number below with your topic number
$topic_number = “25085”;
$myvar = “”;
$query = “SELECT * FROM ipbforums_topics WHERE topic_id=’$topic_number’”;

$show_results = mysqli_query($link, $query);
while($row = mysqli_fetch_array($show_results)){
$topic_id = $row[‘pid’];
$myvar = $topic_id;
}
$query2 = “SELECT * FROM ipbforums_posts WHERE pid=’$myvar’”;
$show_results2 = mysqli_query($link, $query2);
while($row = mysqli_fetch_array($show_results2)){
$topic_post = $row[‘post’];
$myvar = $topic_post;
}
ini_set(‘mbstring.substitute_character’, “none”);
$myvar= mb_convert_encoding($myvar, ‘utf8mb4’);
return “$myvar”;[/php]

In case the OP is still looking for help with this, what exact result is this part of the code producing and how do you know? If all you did is run your application and the end result of saving information elsewhere didn’t happen, how do you know the problem isn’t in the code responsible for saving the information?

Debugging programming problems involves checking what execution path the code is taking, what data the code is operating on as its input, and produce as its output. To do this, you can simply place echo ‘some unique message here’; and var_dump(some_variable_name_here); statements in your code to find what code is being executed and what values are in variables.

Next, do you have php’s error_reporting set to E_ALL and display_errors set to ON, so that php will help you by reporting and displaying all the errors it detects?

Also, do you have any error handling for the database statements? There’s nothing explicit in the code, but there wouldn’t be if you are using exceptions, which is the preferred method, to handle the database statement errors. Are you using exceptions to handle the database statement errors (for the mysqli extension, you would execute some php statements to turn them on immediately prior to making the database connection) and if so, what error(s) are you getting?

Lastly, most of this code and needlessly copying variables to other variables isn’t even needed. You should simply be executing a single JOINed query that gets the data that you want and if the initial topic number is actually coming from external data, you should be using a prepared-query to supply the value to the sql statement when it is executed.

The current code is also getting the LAST post, after the end of the loop? Is that the correct post? The comment in the code indicate the code is supposed to be getting the first post in the topic.

Sponsor our Newsletter | Privacy Policy | Terms of Service