Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

Aruna KN

@Aruna KN
About
Posts
31
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • PHP 8.2 - Unsupported operand types: string * int
    A Aruna KN

    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

    Linux, Apache, MySQL, PHP php help

  • .htaccess Query String Redirect
    A Aruna KN

    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]

    Linux, Apache, MySQL, PHP apache database com tutorial question

  • PHP Warning: Attempt to read property "post_content" on null
    A Aruna KN

    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

    Linux, Apache, MySQL, PHP help php sysadmin announcement

  • Proper parameterised queries for database access
    A Aruna KN

    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

    Linux, Apache, MySQL, PHP php database mysql question

  • Proper parameterised queries for database access
    A Aruna KN

    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

    Linux, Apache, MySQL, PHP php database mysql question

  • Proper parameterised queries for database access
    A Aruna KN

    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'].'

    ';
    }
    }

    ?>

    Linux, Apache, MySQL, PHP php database mysql question

  • Proper parameterised queries for database access
    A Aruna KN

    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'].'

    ';
    }
    }

    ?>

    Linux, Apache, MySQL, PHP php database mysql question

  • PHP Fatal error: Uncaught mysqli_sql_exception
    A Aruna KN

    Sorry Sir..

    Linux, Apache, MySQL, PHP help php database mysql sysadmin

  • PHP Fatal error: Uncaught mysqli_sql_exception
    A Aruna KN

    I decided to remove this post as it's not appropriate to ask huge support for free. Sorry..

    Linux, Apache, MySQL, PHP help php database mysql sysadmin

  • PHP Fatal error: Uncaught mysqli_sql_exception
    A Aruna KN

    Yes I will have to check whole script, this is an old PHP script.

    Linux, Apache, MySQL, PHP help php database mysql sysadmin

  • PHP Fatal error: Uncaught mysqli_sql_exception
    A Aruna KN

    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']);

    Linux, Apache, MySQL, PHP help php database mysql sysadmin

  • PHP Fatal error: Uncaught mysqli_sql_exception
    A Aruna KN

    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?

    Linux, Apache, MySQL, PHP help php database mysql sysadmin

  • PHP Fatal error: Uncaught mysqli_sql_exception
    A Aruna KN

    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

    Linux, Apache, MySQL, PHP help php database mysql sysadmin

  • Only few Errors left before Upgrading to PHP 8.1
    A Aruna KN

    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>

    Linux, Apache, MySQL, PHP database data-structures help php mysql

  • PHP isset for an Array
    A Aruna KN

    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.

    Linux, Apache, MySQL, PHP help question php data-structures announcement

  • PHP isset for an Array
    A Aruna KN

    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);
    }

    Linux, Apache, MySQL, PHP help question php data-structures announcement

  • PHP isset for an Array
    A Aruna KN

    Actually this code was written by an outside person. I will check this further.

    Linux, Apache, MySQL, PHP help question php data-structures announcement

  • PHP isset for an Array
    A Aruna KN

    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 '}'

    Linux, Apache, MySQL, PHP help question php data-structures announcement

  • PHP isset for an Array
    A Aruna KN

    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

    Linux, Apache, MySQL, PHP help question php data-structures announcement

  • PHP Warning: Undefined variable $conn
    A Aruna KN

    Thank you!

    Linux, Apache, MySQL, PHP help php data-structures question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups