Jump to content
  • 0

System News Forums in Website


Haikenz

Question


  • Group:  Members
  • Topic Count:  84
  • Topics Per Day:  0.02
  • Content Count:  309
  • Reputation:   82
  • Joined:  11/15/11
  • Last Seen:  

I'm having a little problem in this IPS forum news system, it works perfectly in PHP 5.x, however I upgraded PHP to 7.1 is experiencing this error ( this system separates categories from the forum to show on the website )

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\forum\connect.php:18 Stack trace: #0 C:\xampp\htdocs\forum\news.php(5): mysql->__construct() #1 {main} thrown in C:\xampp\htdocs\forum\connect.php on line 18

file connect.php

<?php

	error_reporting(0); # remove syntax errors (VertrigoServ / XAMP and others)
	
	DEFINE( 'HOST', 'localhost' );  # Padrão
	DEFINE( 'USER', 'ragnarok' );	# Usuário do pma
	DEFINE( 'PASS', 'ragnarok' );   # Senha do pma
	DEFINE( 'DATABASE', 'forum' );  # Nome da database do fórum
	DEFINE( 'BOARD', 'localhost/forum/' );			# link do seu fórum
	DEFINE( 'LIMIT', '5');          # Limite de Notícias que será exibida
	DEFINE( 'CATEGORY1', '4');      # ID da categoria dos Changelog (coluna forum_id = %)
	DEFINE( 'CATEGORY2', '2');      # ID da categoria das Notícias da Staff (coluna forum_id = %)
	DEFINE( 'CATEGORY3', '5');      # ID da categoria dos Eventos (coluna forum_id = %)
	class	mysql
	{
		public	function	__construct()
		{
				$this->conn = mysql_connect( HOST, USER, PASS ) or die( mysql_error() );
				$this->select = mysql_select_db( DATABASE, $this->conn ) or die( mysql_error() );
		}
		
		public	function	build( $query )
		{
			$this->query = $query;
		}
		
		public	function	execute()
		{
			$this->query = mysql_query( $this->query ) or die( mysql_error() );
		}
		
		public	function	numrows()
		{
			return mysql_num_rows( $this->query );
		}
		
		public	function	fetchassoc()
		{
			return mysql_fetch_assoc( $this->query );
		}
	}

?>

file news.php

<html>
<head>
<?php
	require_once( 'connect.php' );
	$sql = new mysql();
?>
	<?php header("Content-Type: text/html; charset=ISO-8859-1",true);?>
	<style type="text/css">body {	cursor: url("normal.cur"), url("normal.cur"), default;}a { cursor: url("hand.cur"), url("hand.cur"), default; }</style> 
	<style type="text/css">

	@import url(http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100);

	body {
	  font-family: "Roboto", helvetica, arial, sans-serif;
	  font-size: 0px;
	  font-weight: 400;
	  text-rendering: optimizeLegibility;
	}

	div.table-title {
	   display: block;
	  margin: auto;
	  max-width: 600px;
	  padding:5px;
	  width: 100%;
	}

	.table-title h3 {
	   color: #fafafa;
	   font-size: 30px;
	   font-weight: 400;
	   font-style:normal;
	   font-family: "Roboto", helvetica, arial, sans-serif;
	   text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
	   text-transform:uppercase;
	   text-align: center;
	}


	/*** Table Styles **/

	.table-fill {
	  background: white;
	  border-radius:3px;
	  border-collapse: collapse;
	  height: 200px;
	  margin: auto;
	  padding:5px;
	  width: 100%;
	  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
	  animation: float 5s infinite;
	}
	 
	th {
	  color:#D5DDE5;;
	  background:#1b1e24;
	  border-bottom:4px solid #9ea7af;
	  border-right: 1px solid #343a45;
	  font-size:20px;
	  font-weight: 100;
	  padding:15px;
	  text-align:left;
	  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
	  vertical-align:middle;
	}

	th:first-child {
	  border-top-left-radius:3px;
	}
	 
	th:last-child {
	  border-top-right-radius:3px;
	  border-right:none;
	}
	  
	tr {
	  border-bottom-: 1px solid #C1C3D1;
	  color:#666B85;
	  font-size:16px;
	  font-weight:normal;
	  text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
	}
	 
	tr:hover td {
	  background:#fc4242;
	  color:#FFFFFF;
	  border-top: 1px solid #fd5e5e;
	  border-bottom: 1px solid #fd5e5e;
	}
	tr:hover td a {
	  color:#FFFFFF;
	}
	 
	tr:first-child {
	  border-top:none;
	}

	tr:last-child {
	  border-bottom:none;
	}
	 
	tr:nth-child(odd) td {
	  background:#EBEBEB;
	}
	 
	tr:nth-child(odd):hover td {
	  background:#fc4242;
	}

	tr:last-child td:first-child {
	  border-bottom-left-radius:3px;
	}
	 
	tr:last-child td:last-child {
	  border-bottom-right-radius:3px;
	}
	 
	td {
	  background:#FFFFFF;
	  padding:10px;
	  text-align:left;
	  vertical-align:middle;
	  font-weight:300;
	  font-size:16px;
	  text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
	  border-right: 1px solid #C1C3D1;
	}

	td a {
	  color: #666B85;
	  text-decoration: underline;
	}
	td:last-child {
	  border-right: 0px;
	}

	th.text-left {
	  text-align: left;
	}

	th.text-center {
	  text-align: center;
	}

	th.text-right {
	  text-align: right;
	}

	td.text-left {
	  text-align: left;
	}

	td.text-center {
	  text-align: center;
	}

	td.text-right {
	  text-align: right;
	}
		
	</style>
</head>
<body>
	<table class="table-fill">
		<tbody class="table-hover">
			<?php
				$sql->build( "
							SELECT *,
							CASE forum_id
							WHEN ".CATEGORY1." THEN 'noticia'
                            WHEN ".CATEGORY2." THEN 'changelog'
                            WHEN ".CATEGORY3." THEN 'evento'
							END as forum_id
							FROM forums_topics
							WHERE forum_id IN ( '".CATEGORY1."', '".CATEGORY2."','".CATEGORY3."')
							ORDER BY `tid`
							DESC LIMIT 0, ".LIMIT." ");
				$sql->execute();
				while( $app = $sql->fetchassoc() )
				{
					$date = date("d/m", $app['start_date']);
					echo( "<tr>");
					echo( "<td width='10%' class=\"text-left\"><img src=\"{$app['forum_id']}.png\"></td>");
					echo( "<td width='65%' class=\"text-left\"><a href=\"" . BOARD . "topic/{$app['tid']}-{$app['title_seo']}\" class=\"tipsyTIP\" title=\"Clique para ver a not&iacute;cia completa.\" target=\"_blank\">{$app['title']}</td>");
					echo( "<td width='15%' class=\"text-left\"><img src='calendar.png'>  {$date}</td>");
					echo( "</tr>");
				}
			?>
		</tbody>
	</table>
</body>

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3123
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

The MySQL functions (mysql_connect(), mysql_fetch_array(), etc) were removed in PHP 7. You can use the MySQLi extension. http://php.net/manual/en/book.mysqli.php

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  84
  • Topics Per Day:  0.02
  • Content Count:  309
  • Reputation:   82
  • Joined:  11/15/11
  • Last Seen:  

43 minutes ago, Akkarin said:

The MySQL functions (mysql_connect(), mysql_fetch_array(), etc) were removed in PHP 7. You can use the MySQLi extension. http://php.net/manual/en/book.mysqli.php

I'm sorry but I do not understand anything about php and mysql, so I tried to change "mysql" to "mysql" and the error now went to this:

<b>Fatal error</b>:  Uncaught Error: Call to undefined method mysqli::build() in C:\xampp\htdocs\forum\news.php:167
Stack trace:
#0 {main}
  thrown in <b>C:\xampp\htdocs\forum\news.php</b> on line <b>167</b><br />
<?php

	error_reporting(0); # remove syntax errors (VertrigoServ / XAMP and others)
	
	DEFINE( 'HOST', 'localhost' );  # Padrão
	DEFINE( 'USER', 'ragnarok' );	# Usuário do pma
	DEFINE( 'PASS', 'ragnarok' );   # Senha do pma
	DEFINE( 'DATABASE', 'board' );  # Nome da database do fórum
	DEFINE( 'BOARD', 'localhost/forum/' );			# link do seu fórum
	DEFINE( 'LIMIT', '5');          # Limite de Notícias que será exibida
	DEFINE( 'CATEGORY1', '4');      # ID da categoria dos Changelog (coluna forum_id = %)
	DEFINE( 'CATEGORY2', '2');      # ID da categoria das Notícias da Staff (coluna forum_id = %)
	DEFINE( 'CATEGORY3', '5');      # ID da categoria dos Eventos (coluna forum_id = %)
	class	msqli
	{
		public	function	__construct()
		{
				$this->conn = mysqli_connect( HOST, USER, PASS ) or die( mysqli_error() );
				$this->select = mysqli_select_db( DATABASE, $this->conn ) or die( mysqli_error() );
		}
		
		public	function	build( $query )
		{
			$this->query = $query;
		}
		
		public	function	execute()
		{
			$this->query = mysqli_query( $this->query ) or die( mysqli_error() );
		}
		
		public	function	numrows()
		{
			return mysqli_num_rows( $this->query );
		}
		
		public	function	fetchassoc()
		{
			return mysqli_fetch_assoc( $this->query );
		}
	}

?>
<html>
<head>
<?php
	require_once( 'connect.php' );
	$sql = new mysqli();
?>
	<?php header("Content-Type: text/html; charset=ISO-8859-1",true);?>
	<style type="text/css">body {	cursor: url("normal.cur"), url("normal.cur"), default;}a { cursor: url("hand.cur"), url("hand.cur"), default; }</style> 
	<style type="text/css">

	@import url(http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100);

	body {
	  font-family: "Roboto", helvetica, arial, sans-serif;
	  font-size: 0px;
	  font-weight: 400;
	  text-rendering: optimizeLegibility;
	}

	div.table-title {
	   display: block;
	  margin: auto;
	  max-width: 600px;
	  padding:5px;
	  width: 100%;
	}

	.table-title h3 {
	   color: #fafafa;
	   font-size: 30px;
	   font-weight: 400;
	   font-style:normal;
	   font-family: "Roboto", helvetica, arial, sans-serif;
	   text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
	   text-transform:uppercase;
	   text-align: center;
	}


	/*** Table Styles **/

	.table-fill {
	  background: white;
	  border-radius:3px;
	  border-collapse: collapse;
	  height: 200px;
	  margin: auto;
	  padding:5px;
	  width: 100%;
	  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
	  animation: float 5s infinite;
	}
	 
	th {
	  color:#D5DDE5;;
	  background:#1b1e24;
	  border-bottom:4px solid #9ea7af;
	  border-right: 1px solid #343a45;
	  font-size:20px;
	  font-weight: 100;
	  padding:15px;
	  text-align:left;
	  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
	  vertical-align:middle;
	}

	th:first-child {
	  border-top-left-radius:3px;
	}
	 
	th:last-child {
	  border-top-right-radius:3px;
	  border-right:none;
	}
	  
	tr {
	  border-bottom-: 1px solid #C1C3D1;
	  color:#666B85;
	  font-size:16px;
	  font-weight:normal;
	  text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
	}
	 
	tr:hover td {
	  background:#fc4242;
	  color:#FFFFFF;
	  border-top: 1px solid #fd5e5e;
	  border-bottom: 1px solid #fd5e5e;
	}
	tr:hover td a {
	  color:#FFFFFF;
	}
	 
	tr:first-child {
	  border-top:none;
	}

	tr:last-child {
	  border-bottom:none;
	}
	 
	tr:nth-child(odd) td {
	  background:#EBEBEB;
	}
	 
	tr:nth-child(odd):hover td {
	  background:#fc4242;
	}

	tr:last-child td:first-child {
	  border-bottom-left-radius:3px;
	}
	 
	tr:last-child td:last-child {
	  border-bottom-right-radius:3px;
	}
	 
	td {
	  background:#FFFFFF;
	  padding:10px;
	  text-align:left;
	  vertical-align:middle;
	  font-weight:300;
	  font-size:16px;
	  text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
	  border-right: 1px solid #C1C3D1;
	}

	td a {
	  color: #666B85;
	  text-decoration: underline;
	}
	td:last-child {
	  border-right: 0px;
	}

	th.text-left {
	  text-align: left;
	}

	th.text-center {
	  text-align: center;
	}

	th.text-right {
	  text-align: right;
	}

	td.text-left {
	  text-align: left;
	}

	td.text-center {
	  text-align: center;
	}

	td.text-right {
	  text-align: right;
	}
		
	</style>
</head>
<body>
	<table class="table-fill">
		<tbody class="table-hover">
			<?php
				$sql->build( "
							SELECT *,
							CASE forum_id
							WHEN ".CATEGORY1." THEN 'noticia'
                            WHEN ".CATEGORY2." THEN 'changelog'
                            WHEN ".CATEGORY3." THEN 'evento'
							END as forum_id
							FROM forums_topics
							WHERE forum_id IN ( '".CATEGORY1."', '".CATEGORY2."','".CATEGORY3."')
							ORDER BY `tid`
							DESC LIMIT 0, ".LIMIT." ");
				$sql->execute();
				while( $app = $sql->fetchassoc() )
				{
					$date = date("d/m", $app['start_date']);
					echo( "<tr>");
					echo( "<td width='10%' class=\"text-left\"><img src=\"{$app['forum_id']}.png\"></td>");
					echo( "<td width='65%' class=\"text-left\"><a href=\"" . BOARD . "topic/{$app['tid']}-{$app['title_seo']}\" class=\"tipsyTIP\" title=\"Clique para ver a not&iacute;cia completa.\" target=\"_blank\">{$app['title']}</td>");
					echo( "<td width='15%' class=\"text-left\"><img src='calendar.png'>  {$date}</td>");
					echo( "</tr>");
				}
			?>
		</tbody>
	</table>
</body>

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3123
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

The link I gave you has all the information you need.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  84
  • Topics Per Day:  0.02
  • Content Count:  309
  • Reputation:   82
  • Joined:  11/15/11
  • Last Seen:  

my friend was able to change everything, but gave this small mistake, my friend was absent and was needing it now

connect.php

<?php

	// error_reporting(0); # remove syntax errors (VertrigoServ / XAMP and others)
	
	DEFINE( 'HOST', 'localhost' );  # Padrão
	DEFINE( 'USER', 'ragnarok' );       # Usuário do pma
	DEFINE( 'PASS', 'ragnarok' );   # Senha do pma
	DEFINE( 'DATABASE', 'board' );  # Nome da database do fórum
	DEFINE( 'BOARD', 'localhost/forum/' );   # link do seu fórum
	DEFINE( 'LIMIT', '5');          # Limite de Notícias que será exibida
	DEFINE( 'CATEGORY1', '4');      # ID da categoria dos Eventos (coluna forum_id = %)
	DEFINE( 'CATEGORY2', '2');      # ID da categoria das Changelogs da Staff (coluna forum_id = %)
	DEFINE( 'CATEGORY3', '5');      # ID da categoria de Noticías da Staff (coluna forum_id = %)
	
	try {
		$pdo = new PDO("mysql:dbname=".DATABASE.";host=".HOST, USER, PASS);
		
	} catch (PDOException $e) {
		echo "Sua conexão falhou: ".$e->getMessage();
		die();
	}

?>

news.php

<html>
<head>
<?php
	require 'connect.php';
?>
	<?php header("Content-Type: text/html; charset=ISO-8859-1",true);?>
	<style type="text/css">body {	cursor: url("normal.cur"), url("normal.cur"), default;}a { cursor: url("hand.cur"), url("hand.cur"), default; }</style> 
	<style type="text/css">

	@import url(http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100);

	body {
	  font-family: "Roboto", helvetica, arial, sans-serif;
	  font-size: 0px;
	  font-weight: 400;
	  text-rendering: optimizeLegibility;
	}

	div.table-title {
	   display: block;
	  margin: auto;
	  max-width: 600px;
	  padding:5px;
	  width: 100%;
	}

	.table-title h3 {
	   color: #fafafa;
	   font-size: 30px;
	   font-weight: 400;
	   font-style:normal;
	   font-family: "Roboto", helvetica, arial, sans-serif;
	   text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
	   text-transform:uppercase;
	   text-align: center;
	}


	/*** Table Styles **/

	.table-fill {
	  background: white;
	  border-radius:3px;
	  border-collapse: collapse;
	  height: 200px;
	  margin: auto;
	  padding:5px;
	  width: 100%;
	  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
	  animation: float 5s infinite;
	}
	 
	th {
	  color:#D5DDE5;;
	  background:#1b1e24;
	  border-bottom:4px solid #9ea7af;
	  border-right: 1px solid #343a45;
	  font-size:20px;
	  font-weight: 100;
	  padding:15px;
	  text-align:left;
	  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
	  vertical-align:middle;
	}

	th:first-child {
	  border-top-left-radius:3px;
	}
	 
	th:last-child {
	  border-top-right-radius:3px;
	  border-right:none;
	}
	  
	tr {
	  border-bottom-: 1px solid #C1C3D1;
	  color:#666B85;
	  font-size:16px;
	  font-weight:normal;
	  text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
	}
	 
	tr:hover td {
	  background:#fc4242;
	  color:#FFFFFF;
	  border-top: 1px solid #fd5e5e;
	  border-bottom: 1px solid #fd5e5e;
	}
	tr:hover td a {
	  color:#FFFFFF;
	}
	 
	tr:first-child {
	  border-top:none;
	}

	tr:last-child {
	  border-bottom:none;
	}
	 
	tr:nth-child(odd) td {
	  background:#EBEBEB;
	}
	 
	tr:nth-child(odd):hover td {
	  background:#fc4242;
	}

	tr:last-child td:first-child {
	  border-bottom-left-radius:3px;
	}
	 
	tr:last-child td:last-child {
	  border-bottom-right-radius:3px;
	}
	 
	td {
	  background:#FFFFFF;
	  padding:10px;
	  text-align:left;
	  vertical-align:middle;
	  font-weight:300;
	  font-size:16px;
	  text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
	  border-right: 1px solid #C1C3D1;
	}

	td a {
	  color: #666B85;
	  text-decoration: underline;
	}
	td:last-child {
	  border-right: 0px;
	}

	th.text-left {
	  text-align: left;
	}

	th.text-center {
	  text-align: center;
	}

	th.text-right {
	  text-align: right;
	}

	td.text-left {
	  text-align: left;
	}

	td.text-center {
	  text-align: center;
	}

	td.text-right {
	  text-align: right;
	}
		
	</style>
</head>
<body>
	<table class="table-fill">
		<tbody class="table-hover">
			<?php
				$sql = ("
							SELECT *,
							CASE forum_id
							WHEN ".CATEGORY1." THEN 'Changelogs'
							WHEN ".CATEGORY2." THEN 'News'
							WHEN ".CATEGORY3." THEN 'Eventos'
							END as forum_id
							FROM topics
							WHERE forum_id IN ( '".CATEGORY1."', '".CATEGORY2."','".CATEGORY3."')
							ORDER BY `tid`
							DESC LIMIT 0, ".LIMIT." ");
				$sql = $pdo->query($sql);
				if($sql->rowCount() > 0) {
					foreach ($sql->fetchAll() as $app) {
						$date = date("d/m", $app['start_date']);
						echo( "<tr>");
						echo( "<td width='10%' class=\"text-left\"><img src=\"{$app['forum_id']}.png\"></td>");
						echo( "<td width='65%' class=\"text-left\"><a href=\"" . BOARD . "topic/{$app['tid']}-{$app['title_seo']}\" class=\"tipsyTIP\" title=\"Clique para ver a not&iacute;cia completa.\" target=\"_blank\">{$app['title']}</td>");
						echo( "<td width='15%' class=\"text-left\"><img src='calendar.png'>  {$date}</td>");
						echo( "</tr>");
					}
			} else {
					echo("<tr>");
					echo("<td class=\"text-left\" colspan=\"5\" style=\"text-align:center;\">Não há notícias.</td>");
					echo("</tr>");
				}
			?>
		</tbody>
	</table>
</body>

Erro line:

if($sql->rowCount() > 0) {

Msg error:

<b>Fatal error</b>:  Uncaught Error: Call to a member function rowCount() on boolean in C:\xampp\htdocs\forum\news.php:178
Stack trace:
#0 {main}
  thrown in <b>C:\xampp\htdocs\forum\news.php</b> on line <b>178</b><br />

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3123
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

rowCount isn't a standard mysqli function. Use num_rows instead http://php.net/manual/en/mysqli-result.num-rows.php

Link to comment
Share on other sites

×
×
  • Create New...