if (!isset($inactiv)) $inactiv = 0;
else $inactiv = my_time()-$inactiv*2592000;
With PHP 8.2, code line 2 gives following error:
PHP Fatal error: Uncaught TypeError: Unsupported operand types: string * int
Please suggest me a solution
if (!isset($inactiv)) $inactiv = 0;
else $inactiv = my_time()-$inactiv*2592000;
With PHP 8.2, code line 2 gives following error:
PHP Fatal error: Uncaught TypeError: Unsupported operand types: string * int
Please suggest me a solution
I want to redirect URLs with a query string to another query string using .htaccess From: https://example.com/?smp=123456 (Any number after =) To: https://example.com/?p=123456 (Same number as in From URL) Please suggest me a code. I tried following but it's not working.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^/?smp=([0-9]+)$ [NC]
RewriteRule ^$ https://www.example.com/?p=$ [R=301,L]
I’m using a wordpress theme which has not received updates for 2 years, and they’re not giving any support for that theme but I love this theme. After upgrading my server’s PHP version from 7.4 to 8.1 I’m getting an error_log.
PHP Warning: Attempt to read property "post_content" on null in /some-path/wp-content/themes/boldr-lite/functions.php on line 267
PHP Warning: Attempt to read property "post_content" on null in /some-path/wp-content/themes/boldr-lite/functions.php on line 268
I checked the functions.php and line number 267 and 268 as given below:
preg_match( '//', $post->post_content )
|| preg_match( '//', $post->post_content )
And the full function including the above two lines as given below:
/*
* Rewrite and replace wp_trim_excerpt() so it adds a relevant read more link
* when the or quicktags are used
* This new function preserves every features and filters from the original wp_trim_excerpt
*/
function boldr_trim_excerpt( $text = '' ) {
global $post;
$raw_excerpt = $text;
if ( '' === $text ) {
$text = get_the_content( '' );
$text = strip_shortcodes( $text );
$text = apply_filters( 'the_content', $text );
$text = str_replace( ']]>', ']]>', $text );
$excerpt_length = apply_filters( 'excerpt_length', 55 );
$excerpt_more = apply_filters( 'excerpt_more', ' [...]' );
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
/\* If the post\_content contains a OR a quicktag
\* AND the more link has not been added already
\* then we add it now
\*/
if (
(
preg\_match( '//', $post->post\_content )
|| preg\_match( '//', $post->post\_content )
)
&& strpos( $text, $excerpt\_more ) === false
) :
$text .= $excerpt\_more;
endif;
}
return apply\_filters( 'boldr\_trim\_excerpt', $text, $raw\_excerpt );
}
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
add_filter( 'get_the_excerpt', 'boldr_trim_excerpt' );
Please suggest a solution to fix the issue
Finally I was able to solve the code. Here what I did, Old code line:
$query = $conn->prepare("SELECT * FROM ".C_MYSQL_MESSAGES." WHERE (sender_id =? AND receiver_id=?) OR (sender_id =? AND receiver_id=?) ORDER BY `date_added` ASC");
New code line:
$query = "SELECT * FROM ".C_MYSQL_MESSAGES." WHERE (sender_id =? AND receiver_id=?) OR (sender_id =? AND receiver_id=?) ORDER BY `date_added` ASC";
Old code line:
$stmt->bind_param("siis", $_SESSION['m'],(int)$_GET['id'],(int)$_GET['id'],$_SESSION['m']);
New code line:
$stmt->bind_param("siis",$_SESSION['m'],$_GET['id'],$_GET['id'],$_SESSION['m']);
Final Code:
prepare($query);
$stmt->bind_param("siis",$_SESSION['m'],$_GET['id'],$_GET['id'],$_SESSION['m']);
$stmt->execute();
$result = $stmt->get_result();
while($j = mysqli\_fetch\_array($result))
{
$c = mysqli\_query($conn,"UPDATE ".C\_MYSQL\_MESSAGES." SET status=1 WHERE id=".$j\['id'\]);
$class = "";
$date\_class = "";
if($j\['sender\_id'\] == $\_SESSION\['m'\])
{
$class = "right";
$date\_class = "date\_left";
}
else
{
$class = "left";
$date\_class = "date\_right";
}
echo '
'.$j['date_added'].''.$j['message'].'
';
}
}
?>
Thanks for your valuable suggestions to fix this issue
I changed ssss into siis, again it makes an error_log:
[12-Apr-2023 08:04:27 UTC] PHP Fatal error: Uncaught TypeError: mysqli::prepare(): Argument #1 ($query) must be of type string, mysqli_stmt given in /home/student/public_html/friendsphp8/message.php:6
Stack trace:
#0 /home/student/public_html/friendsphp8/message.php(6): mysqli->prepare(Object(mysqli_stmt))
#1 {main}
thrown in /home/student/public_html/friendsphp8/message.php on line 6
After your supportive reply, I rewrote the code after studying the Manual, but it gives an error_log:
[12-Apr-2023 04:15:21 UTC] PHP Fatal error: Uncaught TypeError: mysqli::prepare(): Argument #1 ($query) must be of type string, mysqli_stmt given in /home/student/public_html/friendsphp8/message.php:8
Stack trace:
#0 /home/student/public_html/friendsphp8/message.php(8): mysqli->prepare(Object(mysqli_stmt))
#1 {main}
thrown in /home/student/public_html/friendsphp8/message.php on line 8
My code is as follows: Please suggest me corrections :)
prepare("SELECT * FROM ".C_MYSQL_MESSAGES." WHERE (sender_id =? AND receiver_id=?) OR (sender_id =? AND receiver_id=?) ORDER BY `date_added` ASC");
$stmt = $conn->prepare($query);
$stmt->bind_param("ssss", $_SESSION['m'],(int)$_GET['id'],(int)$_GET['id'],$_SESSION['m']);
$stmt->execute();
$result = $stmt->get_result();
while($j = mysqli\_fetch\_array($result))
{
$c = mysqli\_query($conn,"UPDATE ".C\_MYSQL\_MESSAGES." SET status=1 WHERE id=".$j\['id'\]);
$class = "";
$date\_class = "";
if($j\['sender\_id'\] == $\_SESSION\['m'\])
{
$class = "right";
$date\_class = "date\_left";
}
else
{
$class = "left";
$date\_class = "date\_right";
}
echo '
'.$j['date_added'].''.$j['message'].'
';
}
}
?>
OLD CODE IS AS FOLLOWS:
'.$j['date_added'].''.$j['message'].'
';
}
}
?>
Following code has not been written using proper parameterised queries for database access. I was unable to rewrite it as I'm not an experienced programmer. I am grateful, if anyone can rewrite following code using proper parameterised queries to compatible with PHP 8.1 with MariaDB 10.3
'.$j['date_added'].''.$j['message'].'
';
}
}
?>
Sorry Sir..
I decided to remove this post as it's not appropriate to ask huge support for free. Sorry..
Yes I will have to check whole script, this is an old PHP script.
According to your tips, I was able to fix this issue by adding the following code line:
$_POST['message'] = mysqli_real_escape_string($conn, $_POST['message']);
Actually did you see anything wrong in that code? When trying to store simple text message with ' character (I'm ok brother), it stops processing further and make above mentioned error_log.
mysqli_query($conn,"INSERT INTO ".C_MYSQL_MESSAGES."(`sender_id`,`receiver_id`,`message`) VALUES (".$_POST['sender_id'].",".$_POST['receiver_id'].",'".$_POST['message']."')");
I think
$_POST['message']
part or near has some issue Can you help me to resolve?
I was using a PHP script for a simple message service without any issue upto PHP 7.4, but when I upgrade the PHP version into 8.1, it gives following error_log when trying to send a new message containing "'" eg: I'm ok brother
PHP Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'm ok brother
')' at line 1 in send_message.php:9
Full code of send_message.php
Please suggest me a solution
Only few Errors exists in two PHP files before Upgrading this code to PHP 8.1 Please suggest me solutions, This will fix the whole script Final error_log:
[08-Apr-2023 15:57:03 UTC] PHP Warning: Undefined array key "m" in message.php on line 88
[08-Apr-2023 15:57:03 UTC] PHP Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND receiver_id=36376) OR (sender_id =36376 AND receiver_id=) ORDER BY `date_...' at line 1 in message.php:89
Stack trace:
#0 message.php(101): mysqli_query(Object(mysqli), 'SELECT * FROM p...')
#1 {main}
thrown in message.php on line 89
[08-Apr-2023 15:57:25 UTC] PHP Warning: Undefined array key "id" in inbox.php on line 13
[08-Apr-2023 15:57:25 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at inbox.php:13) in inbox.php on line 13
message.php Code line 88 and 89:
$query = "SELECT * FROM ".C_MYSQL_MESSAGES." WHERE (sender_id =".$_SESSION['m']." AND receiver_id=". (int)$_GET['id'].") OR (sender_id =".(int)$_GET['id']." AND receiver_id=".$_SESSION['m'].") ORDER BY `date_added` ASC";
$result = mysqli_query($conn,$query) or die();
Complete code of message.php
= '7'");
$count=mysqli\_num\_rows($tmp);
$row=mysqli\_fetch\_array($tmp);
$from\_name=$row\['fname'\].' '.$row\['lname'\];
$from\_id = $row\['id'\];
if($count == '0') {
$error = 1;
}
}
else
{
$error = 1;
}
if($error == 1)
{
header('location: '.C_URL.'/inbox.php');
die();
}
if(!isset($_SESSION['m']) || $_SESSION['m'] == '')
{
header('location: '.C_URL.'/login.php?redirect_url='.C_URL.'/message.php?id='. (int)$_GET['id']);
}
include_once 'templates/'.C_TEMP.'/config.php';
include_once 'templates/'.C_TEMP.'/header.php';
?>
p.msgtext{
width: 80%;
clear: both;
</x-turndown>
You are correct Richard, it's bit hard but your code suggestion worked for another code line in the same PHP code, see my last reply.
Actually issue has been fixed after adding your code suggestion to another place in the same PHP file:
$tm=array($sendid,'____',C_SNAME);
$message=template($w[588],$tm);
sendmail(C_FROMM,$i['email'],$subject,$message,'text');
}
$sendid = '';
global $sendid;
printm($str.$sendid);
}
Actually this code was written by an outside person. I will check this further.
I tried using your code suggestion but when user recieved verification email and clicked on verify link, it gives "HTTP ERROR 500". Also error_log has following: PHP Parse error: syntax error, unexpected 'global' (T_GLOBAL), expecting case (T_CASE) or default (T_DEFAULT) or '}'
Previously with help of this forum I was able to fix Undefined variable errors using if(isset()) for PHP 8.1. But this time I was unable to use if(isset()) to fix this error_log: PHP Warning: Undefined variable $sendid in /home/____/check.php on line 70 Code line 70 is
printm($str.$sendid);
As above line connected with an array, how can I use isset? Please suggest me a solution. Full code is given below:
DATE_SUB(NOW(), INTERVAL ".C_REG_DAYS." DAY)");
$row=mysqli_fetch_array($temp);
$count = $row['total'];
if($count != '0') {
mysqli_query($conn,"DELETE FROM ".C_MYSQL_TEMP." WHERE id='".$id."' AND code='".$code."'");
if(C_CHECK_REGISTER == '3') {
$status='1';
$str=$w[159];
}
else {
$status='7';
$str = $w[46];
}
mysqli_query($conn,"UPDATE ".C_MYSQL_MEMBERS." SET status='".$status."' WHERE id='".$id."'");
$result = mysqli_query($conn,'SELECT email, password FROM '.C_MYSQL_MEMBERS.' WHERE id = \''.$id.'\'');
while($i=mysqli_f
Thank you!