Skicka med $conn till mysqli_error så ser du vad du får för fel.
Hejsan!
Håller på att bli galen... Har hållt på hela kvällen med att försöka fixa så att mina nyheter som jag skriver ska visas på startsidan men jag får det inte till att fungera!
Det som är konstigt är att jag har gjort likadant i admin/list_news.php och där fungerar det utan att felmeddelandet kommer upp som lyder:
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\martin\includes\show_news.php on line 8
Tacksam för all hjälp!
(Kan bero på att jag är trött också att jag inte hittar felet, men ja, hoppas på hjälp iaf)
includes/show_news.php
<?php
include('conn.php');
//create database connection
$conn = dbConnect('query');
//prepare the SQL query
$sql = 'SELECT * FROM nyheter ORDER by datum DESC';
//process the query
$result = $conn->query($sql) or die(mysqli_error());
//if successful, print it out
while ($row = $result->fetch_assoc()) {
?>
<p id="rubrik"><?=$row['title']?></p>
<p id="stycke"><?=$row['article']?></p>
<p id="skribent">Skrivit av: <b><?=$row['writer']?></b>, <i><?=$row['datum']?></i></p>
<?php
}
?>
includes/conn.php
<?php
function dbConnect($type) {
if ($type == 'query') {
$user = 'member';
$pwd = 'test';
}
elseif ($type == 'admin') {
$user = 'Martin';
$pwd = 'test';
}
else {
exit('Unrecognized connection type');
}
$conn = new mysqli('localhost', $user, $pwd, 'martinsnest')
or die ('Cannot open database');
return $conn;
}
?>
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Martin's Nest</title>
<link href="stil.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="container">
<div id="header" align="center">
<img src="images/header.jpg" border="0" />
</div>
<ul id='menu'>
<li><a href="index.php">Startsida</a></li>
<li><a href="register.php">Bli medlem</a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href="faq.php">F.A.Q</a></li>
<li><a href="contact.php">Kontakta</a></li>
</ul>
<ul id='menur'>
<li><a href="admin/index.php">Administration</a></li>
</ul>
<div id="main">
<p> </p>
<table>
<tr>
<td id="border" valign="top">
<p id="litenrubrik">
Senaste nyheter
</p>
</td>
<td id="border" valign="top">
<?php
include('includes/show_news.php');
?>
</td>
</tr>
</table>
</div>
<div id="footer">
<?php
include('includes/link.php');
?>
</div>
</div>
</div>
</body>
</html>