Ok I am learning php and trying out classes and functions. Currently I have multiple pages where it has the same menu bar and user info so I decided to create a class Common and a function menu to load user info and echo info and menu content. For some reason it is not displaying anything help?
class Content {
public function menu($userid) {
require_once("../class/class1.php");
echo '<div id="logo"></div>
<div style="clear:both;"></div>';
echo '<div id="user">Welcome ';
$db = new MySQL();
$user = new User();
$sql = $db->sql($user->loadUser($userid));
if ($db->num_rows($sql) > 0) {
while ($row = $db->fetch_array($sql)) {
echo $row['name'] . ' ' . $row['lastname'];
}
}
}
}
HTML:
require_once("content.php");
$content = new Content();
echo $content->menu($userid);
when running in localhost i get the following error:
Fatal error: Cannot redeclare class Sql in C:\xampp\htdocs\orbecargo\class\sql.php on line 3
that file is:
class MySQL
{
private $conexion;
private $total_consultas;
public function MySQL(){
if(!isset($this->conexion)){
$this->conexion = (mysql_connect("server","username","password")) or die(mysql_error());
mysql_select_db("database",$this->conexion) or die(mysql_error());
mysql_set_charset('utf8',$this->conexion);
}
}
}
the weird thing is that other pages work perfectly…
and I removed the
echo $content->menu($userid);
and still nothing
menu() does not return anything
remove the echo before the menu(); to