New To Php - Need Some Help

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
seanphpwannabe
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Sep 08, 2017 9:19 pm

Mon Sep 11, 2017 8:48 pm

Hello All,

Very nice to be a part of the forums here.

I have been working on a little chat project. I have been able to I think figure out most of the errors and/or problems.

However with that being said I am facing the following error,
Fatal error: Uncaught Error: Call to undefined function arrary() in C:\xampp\htdocs\ChatAPP\functions\chat.func.php:8 Stack trace: #0 C:\xampp\htdocs\ChatAPP\index.php(17): get_msg() #1 {main} thrown in C:\xampp\htdocs\ChatAPP\functions\chat.func.php on line 8

Here are my pages
Index.php

Code: Select all

<?php 
	require ('db/connect.db.php');
	require ('functions/chat.func.php');

	if(isset($_POST['send'])){
		if (send_msg($_POST['sender'], $_POST['message'])){
			echo "Message Sent";
		} else {
			echo "Message Failed To Send";
		}
	}

?>

<div id="messages">
<?php
$messages = get_msg();
foreach($message as $message) {
	echo $message['sender']."Sent<br>";
	echo $message['message']."<br>";
}
?>
</div>
<form action="index.php" method="post">
<labal>Enter Name: <input type="text" name="sender"></labal>
<label>Enter Message:<input type="text" name="message"></label>
<input type="submit" name="send" value="Send Message">
</form>
Here is chat.func.php

Code: Select all

<?php 

	function get_msg() {
		$query = "SELECT * 'Sender','Message' FROM 'chat'";

		//$run = mysqli_query($query);

		$message = arrary();

		while($message = mysqli_fetch_assoc($run)) {
			$message[] =array('sender'=>$message['Sender'],
							  'message'=>$message['Message']);
		}
		return $messages;
	}

	function send_msg($sender, $message) {
		if(!empty($sender) && !empty($message)){

			$sender = mysqli_real_escape_string($sender);
			$message = mysqli_real_escape_string($message);

			$query = "INSERT INTO 'chat'. 'chat' VALUES(null, '{$sender}', '$message') ";

			if($run = mysqli_query($query)) {
				return true;
			} else {
				return false;
			}

		} else {
			return false;
		}
	}


 ?>

The other two pages are my connect.db.php file which is working and core.inc.php file.

I could really use the help.

Thank you,
Sean

Phi11W
New php-forum User
New php-forum User
Posts: 5
Joined: Thu Aug 17, 2017 3:37 am

Tue Sep 12, 2017 2:46 am

$message = arrary();
I think you mean:

Code: Select all

$message = array();

seanphpwannabe
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Sep 08, 2017 9:19 pm

Tue Sep 12, 2017 3:51 am

Hello Phi11W,

Thank you for your response.

I saw what you were referencing to, and feel like an idiot now.

However, after correcting this I have now run into the following,

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\ChatAPP\functions\chat.func.php on line 6

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\ChatAPP\functions\chat.func.php on line 10

Notice: Undefined variable: message in C:\xampp\htdocs\ChatAPP\index.php on line 18

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\ChatAPP\index.php on line 18

chorn
php-forum Active User
php-forum Active User
Posts: 405
Joined: Fri Apr 01, 2016 2:18 am

Tue Sep 12, 2017 6:41 am

on procedural usage, mysqli_query needs the connection, refer to the manual:

http://php.net/manual/en/mysqli.query.php

Post Reply