I am currently learning PHP, but I have run into a problem.
I have a class that allows you to create an event and set/get its name, date, description and price. It is currently in a file called "class_lib.php".
<?php
class Eventitem
{
private $eventName;
private $eventDate;
private $eventDesc;
private $eventPrice;
function __construct()
{
$this->eventName = "BLANK";
$this->eventDate = "January 1";
$this->eventDesc = "...";
$this->eventPrice = "$0.00";
}
public function setName($name)
{
$this->eventName = $name;
}
public function getName()
{
return $this->eventName;
}
public function getDate()
{
return $this->eventDate;
}
public function getDesc()
{
return $this->eventDesc;
}
public function getPrice()
{
return $this->eventPrice;
}
}
?>
Now, in another file that I'm using as a testbed, called "blank.php", I tried to define the class and use its setName and getName methods:
<head>
</head>
<body>
<div id="content">
<?php include 'class_lib.php'; ?>
<?php
$event = new Eventitem();
$event->setName("Some Event");
echo $event->getName();
?>
</div>
</body>
<footer>
</footer>
However, when I execute it, nothing shows up! What am I doing wrong?
I've copied and pasted your code onto my localhost and it works fine.
What you have here is an issue running php scripts via whatever web server you're trying to use. Make sure you can get any php script running, such as <?php phpinfo(); ?>
.