Click here to Skip to main content
15,884,298 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: PHP Fatal error: Uncaught mysqli_sql_exception Pin
Aruna KN11-Apr-23 4:57
Aruna KN11-Apr-23 4:57 
QuestionHow To Find 'DOES NOT CONTAIN' or 'DOES CONTAIN' in Php ? Pin
Member 159745539-Apr-23 10:27
Member 159745539-Apr-23 10:27 
AnswerRe: How To Find 'DOES NOT CONTAIN' or 'DOES CONTAIN' in Php ? Pin
Richard MacCutchan9-Apr-23 22:20
mveRichard MacCutchan9-Apr-23 22:20 
QuestionHow To Order By Adding Columns Values In SQL? Pin
Member 159745539-Apr-23 10:25
Member 159745539-Apr-23 10:25 
AnswerRe: How To Order By Adding Columns Values In SQL? Pin
jschell10-Apr-23 5:57
jschell10-Apr-23 5:57 
GeneralRe: How To Order By Adding Columns Values In SQL? Pin
Member 1597455310-Apr-23 6:35
Member 1597455310-Apr-23 6:35 
GeneralRe: How To Order By Adding Columns Values In SQL? Pin
jschell11-Apr-23 4:36
jschell11-Apr-23 4:36 
QuestionOnly few Errors left before Upgrading to PHP 8.1 Pin
Aruna KN8-Apr-23 6:40
Aruna KN8-Apr-23 6:40 
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:


PHP
$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

PHP
<?php
@session_start();
$error = "";

include_once 'include/config.inc.php';
include_once 'include/options.inc.php';
include_once 'include/security.inc.php';
include_once 'include/functions.inc.php';
$from_name = "";
$from_id ="";
if(isset($_GET['id']) && $_GET['id'] != "")
{
	
	$receiver_id = (int)$_GET['id'];
	
	$tmp=mysqli_query($conn,"SELECT id,fname,lname FROM ".C_MYSQL_MEMBERS." WHERE id=".$receiver_id." AND status >= '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';
 ?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
p.msgtext{
	width: 80%;
	clear: both;
	padding: 10px 5px;
    border-radius: 5px;
}
.left{
    background-color: #edf9f9;
    float: left;
	text-align: left;
}
.right{
    background-color: #f3f3f3;
    float: right;
	text-align: right;
}
.date_left
{
	float: left;
    font-size: 11px;
    padding: 14px 1px 0px;
    color: #adadad;
}
.date_right
{
	float: right;
    font-size: 11px;
    padding: 14px 1px 0px;
    color: #adadad;
}
</style>
<br>
<div class="row">
<br/><br/>
</div>
<div class="col-md-12" style="padding-top: 10px;">
      <div class="panel panel-default">
	   <div class="panel-heading" style=" background-color: <?php echo COLORH ?>"><?php echo $from_name ?>  [<a href="<?php echo C_URL ?>/view.php?l=default&id=<?php echo $from_id ?>"><?php echo $from_id ?></a>]</div>
        <div class="panel-body"  style=" background-color: <?php echo COLOR1 ?>">
		<div id="messages">
   <?php
        if(isset($_GET['id']) && $_GET['id'] != "")
		{
			 $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();

		     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 '<p class="msgtext '.$class.'">'.$j['date_added'].''.$j['message'].'</p>';	
			}
		}
   
  ?>
</div>
<div class="col-md-6" style="float: none;margin: auto;">
 <form method="post" onsubmit="return false;" id="send_message" action="send_message.php">
    <input  type="hidden" name="sender_id" value="<?php if(isset($_SESSION['m']))echo $_SESSION['m'] ?>" />
	<input  type="hidden" name="receiver_id" value="<?php echo $receiver_id ?>" />
	<textarea class="form-control" id="message_box" name="message"></textarea>
	<br/>
	<a class="btn btn-success" style="float:right;color: white" id="send_message_btn" href="javascript:;">Send</a>
	
 </form>
</div>
</div>
</div>

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>

$('#send_message_btn').click(function(){
	
	var url = "send_message.php"; 

    $.ajax({
           type: "POST",
           url: url,
           data: $("#send_message").serialize(), // serializes the form's elements.
           success: function(data)
           {
			   if(data.trim() == '1')
			   {
				   $('#message_box').val('');
			   }
               // show response from the php script.
           }
         });

   
	
});
function load_messages()
{
	$.ajax({
           type: "POST",
           url: "load_messages.php",
           data: {id: <?php echo $receiver_id ?>}, // serializes the form's elements.
           success: function(data)
           {
			   if(data.trim() != '')
			   {
				   $('#messages').append(data);
			   }
			   
           }
         });
}
setInterval(function(){ 
    load_messages();
}, 3000);

</script>
<?php include_once 'templates/'.C_TEMP.'/footer.php'; ?>


inbox.php

Code line 13:

PHP
header('location: '.C_URL.'/login.php?redirect_url='.C_URL.'/inbox.php'.$_GET['id']);


Complete code of inbox.php

PHP
<?php
@session_start();
$error = "";

include_once 'include/config.inc.php';
include_once 'include/options.inc.php';
include_once 'include/security.inc.php';
include_once 'include/functions.inc.php';
include_once 'templates/'.C_TEMP.'/config.php';

if(!isset($_SESSION['m']) || $_SESSION['m'] == '')
{
	header('location: '.C_URL.'/login.php?redirect_url='.C_URL.'/inbox.php'.$_GET['id']);
	exit;
}

include_once 'templates/'.C_TEMP.'/header.php';
 ?>

<?php 
    $unsubscribe_token = '';
    $user = [];
    $tmp=mysqli_query($conn,"SELECT id, purposes, gender, country, email, email_subscription FROM ".C_MYSQL_MEMBERS." WHERE id='".$_SESSION['m']."' AND status >= '7'");
        if($tmp) {
            $user=mysqli_fetch_array($tmp);

	        $unsubscribe_token = $user['id'].'-'.$user['gender'].'-'.$user['purposes'].'-'.$user['country'];   
        }
	    
	   
 ?>
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">-->
<style>
p.msgtext{
	clear: both;
	padding: 10px 5px;
	margin-bottom: 2px;
	cursor: pointer;
	background-color: #f3f3f3;
}
.name_class{   
    float: left;
    font-weight: 600;
    color: #131312;
    margin-right: 20px;
}

.date_class
{
	float: right;
    font-size: 12px;
    color: #adadad;
}
</style>
<br>
<div id="messages" class="col-md-12" style="padding-top: 10px;">
 <div class="panel panel-default">
	   <div class="panel-heading" style=" background-color: <?php echo COLORH ?>"><?php echo $w[585] ?></div>
        <div class="panel-body"  style=" background-color: <?php echo COLOR1 ?>">
   <?php 
   
   if($conn == null) {
       $conn = mysqli_connect(C_HOST,C_USER,C_PASS,C_BASE) or die($w[113]);
   }
   $query = "SELECT pro_messages.*,sender.fname as sender_fname,receiver.fname as receiver_fname,sender.lname as sender_lname,receiver.lname as receiver_lname FROM ".C_MYSQL_MESSAGES." INNER JOIN ".C_MYSQL_MEMBERS." sender ON sender.id=pro_messages.sender_id INNER JOIN ".C_MYSQL_MEMBERS." receiver ON receiver.id=pro_messages.receiver_id WHERE sender_id =".$_SESSION['m']." OR receiver_id=".$_SESSION['m']." ORDER BY `date_added` desc";
            
			 $result = mysqli_query($conn,$query);
             $temp = array();
			 $num = 1;
			 
			 
             while($j = mysqli_fetch_array($result))
			{	
				$name = "";
				$id="";
				if($j['receiver_id'] == $_SESSION['m'])
				{
					    if(!in_array($j['sender_id'], $temp))
						{
						   $temp[] = $j['sender_id'];
						}
						else
							continue;
						$id = $j['sender_id'];
						$name = $j['sender_fname'].' '. $j['sender_lname'];
				}
				elseif($j['sender_id'] == $_SESSION['m'])
				{
					    if(!in_array($j['receiver_id'], $temp))
						{
						   $temp[] = $j['receiver_id'];
						}
						else
							continue;
					$id = $j['receiver_id'];
					$name = $j['receiver_fname'].' '. $j['receiver_lname'];
				}
					
				echo '<p class="msgtext"> <a style="color: black;font-size: 16px;" href="message.php?id='.$id.'">'.$num.') '.$name.''.$j['message'].'</a>'.$j['date_added'].'</p>';	
			    $num++;
			}
			
	if(!empty($user)) {
        $action = $user['email_subscription'] == 1 ? 'unsubscribe': 'subscribe';
  ?>
   
   <a href="<?php echo C_URL ?>/email_subscription.php?token=<?php echo $unsubscribe_token ?>&action=<?php echo $action ?>"><?php echo $user['email_subscription'] == 1 ? 'Unsubscribe': 'Subscribe' ?> to Email Updates</a>
   <?php } ?>
   </div>
</div>
<?php include_once 'templates/'.C_TEMP.'/footer.php'; ?>

QuestionPHP isset for an Array Pin
Aruna KN6-Apr-23 4:51
Aruna KN6-Apr-23 4:51 
AnswerRe: PHP isset for an Array Pin
Richard MacCutchan6-Apr-23 6:06
mveRichard MacCutchan6-Apr-23 6:06 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:06
Aruna KN8-Apr-23 5:06 
GeneralRe: PHP isset for an Array Pin
Richard MacCutchan8-Apr-23 5:09
mveRichard MacCutchan8-Apr-23 5:09 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:19
Aruna KN8-Apr-23 5:19 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:25
Aruna KN8-Apr-23 5:25 
GeneralRe: PHP isset for an Array Pin
Richard MacCutchan8-Apr-23 5:33
mveRichard MacCutchan8-Apr-23 5:33 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:55
Aruna KN8-Apr-23 5:55 
QuestionPHP Warning: Undefined variable $conn Pin
Aruna KN3-Apr-23 2:45
Aruna KN3-Apr-23 2:45 
AnswerRe: PHP Warning: Undefined variable $conn Pin
Richard MacCutchan3-Apr-23 2:50
mveRichard MacCutchan3-Apr-23 2:50 
GeneralRe: PHP Warning: Undefined variable $conn Pin
Aruna KN3-Apr-23 3:48
Aruna KN3-Apr-23 3:48 
QuestionPHP 8.1 Count issue Pin
Aruna KN30-Mar-23 0:06
Aruna KN30-Mar-23 0:06 
AnswerRe: PHP 8.1 Count issue Pin
Richard MacCutchan30-Mar-23 0:45
mveRichard MacCutchan30-Mar-23 0:45 
AnswerRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 0:45
mveRichard Deeming30-Mar-23 0:45 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 1:38
Aruna KN30-Mar-23 1:38 
GeneralRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 2:53
mveRichard Deeming30-Mar-23 2:53 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 3:21
Aruna KN30-Mar-23 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.