I'm doing a php based project.And I want to add data to the database.I did it using php, PDO. And I created the code with OOC. But There's a if else part in main HTML page. In that part the else part is running. But I didn't even click the insert button. When the page is loading the else part is running. I watched a video and this code is working perfectly fine. Here's the code..
Insert.php - Getters, Setters, SQL query and etc.
class Stock
{
protected $ItemNo;
protected $ItemName;
protected $brand;
protected $qty;
protected $Description;
protected $ItemDate;
protected $SupplierName;
protected $SupplierMail;
private $tableName = 'StockDetails';
private $dbconn;
function setItemNo($ItemNo) { $this->ItemNo = $ItemNo; }
function getItemNo() { return $this->ItemNo; }
function setItemName($ItemName) { $this->ItemName = $ItemName; }
function getItemName() { return $this->ItemName; }
function setBrand($brand) { $this->brand = $brand; }
function getBrand() { return $this->brand; }
function setQty($qty) { $this->qty = $qty; }
function getQty() { return $this->qty; }
function setDescription($Description) { $this->Description = $Description; }
function getDescription() { return $this->Description; }
function setItemDate($ItemDate) { $this->ItemDate = $ItemDate; }
function getItemDate() { return $this->ItemDate; }
function setSupplierName($SupplierName) { $this->SupplierName = $SupplierName; }
function getSupplierName() { return $this->SupplierName; }
function setSupplierMail($SupplierMail) { $this->SupplierMail = $SupplierMail; }
function getSupplierMail() { return $this->SupplierMail; }
public function __construct()
{
require_once ('Database.php');
$db = new Database();
$this->dbconn = $db->connect();
}
public function insert(){
$sql = "INSERT INTO $this->tableName VALUES (:ItemNo, :ItemName, :brand, :qty, :Description, :ItemDate, :SupplierName, :SupplierMail)";
$stmt = $this->dbconn->prepare($sql);
$stmt->bindParam(':ItemNo', $this->ItemNo);
$stmt->bindParam(':ItemName', $this->ItemName);
$stmt->bindParam(':brand', $this->brand);
$stmt->bindParam(':qty', $this->qty);
$stmt->bindParam(':Description', $this->Description);
$stmt->bindParam(':ItemDate', $this->ItemDate);
$stmt->bindParam(':SupplierName', $this->SupplierName);
$stmt->bindParam(':SupplierMail', $this->SupplierMail);
if($stmt->execute()){
return true;
}else{
return false;
}}}
?>
Action.php - Form action on AddItem.php
require_once ('Insert.php');
class action{
function __construct(){
switch ($_POST['submit']) {
case 'insert':
$obInsert = new Stock;
$obInsert->setItemNo($_POST['ItemNo']);
$obInsert->setItemName($_POST['ItemName']);
$obInsert->setBrand($_POST['brand']);
$obInsert->setQty($_POST['qty']);
$obInsert->setDescription($_POST['Description']);
$obInsert->setItemDate(date('Y-m-d H:i:s'));
$obInsert->setSupplierName($_POST['SupplierName']);
$obInsert->setSupplierMail($_POST['SupplierMail']);
if($obInsert->insert()) {
header('location: AddItem.php?insert=1');
} else{
header('location: AddItem.php?insert=0');
}
break;
default:
header('location: AddItem.php');
break;
}
}
}
if(isset($_POST['submit'])){
$object = new action;
}
AddItem.php
To get the brand and ItemName from the Database. The brand changes according to ItemName.
<?php
require_once ('GetBrand.php');
$ItemName = LoadItemName();
?>
$(document).ready(function(){
$("#ItemName").change(function(){
var aid = $("#ItemName").val();
$.ajax({
url: 'GetBrand.php',
method: 'post',
data: 'aid=' + aid
}).done(function(brand){
console.log(brand);
brand = JSON.parse(brand);
$('#brand').empty();
brand.forEach(function(bnamee){
$('#brand').append('<option>' + bnamee.brand + '</option>')
})
})
})
})
The Form
<form name="form0" method="post" action="Action.php">
<div class="form-group">
<label for="text">Item No</label>
<input type="text" name="ItemNo" id="ItemNo" placeholder="Item No" required>
</div>
<form name="form1" action="AddItem.php" method="post">
<div class="form-group">
<label for="text">Item Name</label>
<table>
<tr>
<td><select name="ItemName" id="ItemName" required>
<option value="" disabled="" selected>Select Name</option>
<?php foreach($ItemName as $iname)
echo "<option id='".$iname['ItemNo']."' value='".$iname['ItemNo']."'>".$iname['ItemName']."</option>";
?>
</select></td>
<td><label for="text">Add Item Name : </label></td>
<td><input type="text" name="name" id="name"> </td>
<td><button>Add</button></td>
</tr>
</table>
</div>
<div class="form-group">
<label for="text">Brand Name</label>
<table>
<tr>
<td><select name="brand" id="brand" required>
<option value="">Select Brand</option>
</select></td>
<td<label for="text">Add Brand : </label></td>
<td><input type="text" name="Bname" id="Bname" class="form-control" > </td>
<td><button>Add</button></td>
</tr>
</table>
</div>
</form>
<div class="form-group">
<label for="text">Quantity</label>
<input type="text" name="qty" id="qty" placeholder="Quantity" required>
</div>
<div class="form-group">
<label for="text">Item Description</label>
<input type="text" name="Description" id="Description" placeholder="Description" required>
</div>
<div class="form-group">
<label for="text">Date</label>
<input type="date" name="ItemDate" id="ItemDate" required>
</div>
<div class="form-group">
<label for="text">Supplier Name</label>
<input type="text" name="SupplierName" id="SupplierName" placeholder="Supplier Name" required>
</div>
<div class="form-group">
<label for="text">Supplier Mail</label>
<input type="text" name="SupplierMail" id="SupplierMail" placeholder="Supplier Mail" required>
</div><br/>
<div class="form-group">
<button id="submit" name="submit" value="insert">Insert</button>
<?php
if(isset($_GET['insert']) && ($_GET['insert'] == 1)){
echo "Inserted Successfully ";
}else // This else part is running when the page is loading
echo "Ooops..! Something went wrong.";
}
?>
</div>
</form>
<?php
if(isset($_GET['insert']) && ($_GET['insert'] == 1)){
echo "Inserted Successfully ";
}else // This else part is running when the page is loading
echo "Ooops..! Something went wrong.";
}
?>
you are surprised that this runs?
What you have said here is, if there is a $_GET parameter called insert and it's equal to 1 then echo "inserted..." in any other situation that may exist echo 'oops...'
Php cannot naturally discern whether this is the initial page load, a redirect, a button has been pressed or what you are thinking. If you only want this to run if a button has been been clicked you'd need to add in some extra checks around the whole thing, for example
if(isset($_POST['submit'])) {
///add in your checks to
}
or possibly more suitable for you would be
if(isset($_GET['insert']) {
if($_GET['insert'] == 1)){
echo "Inserted Successfully ";
} else {// you're missing a brace here
echo "Ooops..! Something went wrong.";
}
}
the point is, your code will always run regardless at the moment because it is an if/else i.e. do this or do that - but what you want to say is if a - do b or c, else do nothing. I think you need to try and understand exactly how conditionals work
Related
Problem is: If I write the wrong input for example: under username the number of character must be from 2-25 and I write only one character then error is shown and after I refresh the page the error doesn't go. How to remove the validation error after I refresh the page. There are three files: register.php Account.php and register-handlers.php
register.php
<!DOCTYPE html>
<?php
include("includes/classes/Accounts.php");
$account1 = new Accounts();
include("includes/handlers/register-Handlers.php");
?>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Register your free account</title>
</head>
<body>
<div id="inputContainer">
<form id="loginForm" action="login.php" method="POST">
<h2> Login to your account</h2>
<p>
<label for="loginusername">Username</label>
<input type="text" id="loginusername" placeholder="eg:shaahil" required>
</p>
<p>
<label for="loginpassword">password</label>
<input type="password" id="loginpassword" placeholder="type your password" required>
</p>
<button type="submit" name="LOGINB">Login</button>
</form>
</div>
<form id="registerpage" action="register.php" method="POST">
<h2>Create your free account</h2>
<p>
<?php echo $account1 -> getError("the character must be between 5 to 25 "); ?>
<label for="username1">Username</label>
<input type="text" name="username1" id="username1" placeholder="username" required>
</p>
<p>
<?php echo $account1->getError("your first name must have character between 2 to 25 ");?>
<label for="firstname">First name</label>
<input name="firstname" type="text" id="firstname" placeholder="eg:shaahil" required>
</p>
<p>
<?php echo $account1->getError("your last name must have character between 2 to 25 ");?>
<label for="lastname">Last name</label>
<input name="lastname" type="text" id="lastname" placeholder="eg:abraham" required>
</p>
<p>
<?php echo $account1->getError("invalid password ");?>
<?php echo $account1->getError("abc");?>
<?php echo $account1->getError("the password must be between 5 to 25 characters");?>
<label for="password">Password</label>
<input name="password" type="password" id="password" placeholder="enter your password" required>
</p>
<p>
<label for="password1">Confirm password</label>
<input name="password1" id="password1" type="password" placeholder="Confirm your password" required>
</p>
<p>
<?php echo $account1->getError("Email is invalid");?>
<label for="email1">Email</label>
<input name="email1" type="email" id="email1" placeholder="enter your email" required>
</p>
<button type="submit" name="Registerbutton">Register</button>
</form>
</body>
</html>
register-handlers.php
<?php
function sanitizeFormUsername($inputText){
$inputText = strip_tags($inputText);
$inputText=str_replace(" ","",$inputText);
$inputText=ucfirst(strtolower($inputText));
return $inputText;
}
function sanitizeFormString($inputText){
$inputText = strip_tags($inputText);
$inputText=str_replace(" ","",$inputText);
$inputText=ucfirst(strtolower($inputText));
return $inputText;
}
function sanitizeFormEmail($inputText){
$inputText=strip_tags($inputText);
$inputText=str_replace(" ","",$inputText);
return $inputText;
}
function sanitizeFormPassword($inputText){
$inputText=strip_tags($inputText);
return $inputText;
}
if(isset($_POST['Registerbutton'])){
$username1 = sanitizeFormUsername($_POST['username1']);
$firstname = sanitizeFormUsername($_POST['firstname']);
$lastname = sanitizeFormUsername($_POST['lastname']);
$email1 = sanitizeFormEmail($_POST['email1']);
$password= sanitizeFormPassword($_POST['password']);
$password1= sanitizeFormPassword($_POST['password1']);
$wasSuccessful = $account1->register($username1, $firstname, $lastname, $email1, $password, $password1);
if($wasSuccessful==true){
header("Location: index.php");
}
?>
Accounts.php
<?php
class Accounts{
private $errorArray;
public function __construct(){
$this->errorArray = array();
}
public function register($un1, $fn1, $ln, $em, $ps, $ps1)
{
$this->validateusername($un1);
$this->validatefirstname($fn1);
$this->validatelastname($ln);
$this->validateemail1($em);
$this->validatepasswords($ps,$ps1);
if(empty($this->errorArray) == true){
return true;
}
else {
return false;
}
}
public function getError($error) {
if(!in_array($error, $this->errorArray)) {
$error = "";
}
return " <span class='errorMessage'>$error</span> ";
}
private function validateusername($un){
if(strlen($un) > 25 || strlen($un) < 5 ){
array_push($this->errorArray , "the character must be between 5 to 25 ");
return;
}
}
private function validatefirstname($fn){
if(strlen($fn) > 25 || strlen($fn) < 2){
array_push($this->errorArray , "your first name must have character between 2 to 25 ");
return;
}
}
private function validatelastname($ln){
if(strlen($ln)>25 || strlen($ln)<2){
array_push($this ->errorArray , "your last name must have character between 2 to 25 ");
return;
}
}
private function validatepasswords($ps,$ps1){
if($ps!=$ps1){
array_push($this ->errorArray , "invalid password ");
return;
}
if(preg_match('/[^A-Za-z0-9]/', $ps)) {
array_push($this->errorArray, "abc");
return;
}
if(strlen($ps)>25 || strlen($ps)<5){
array_push($this->errorArray , "the password must be between 5 to 25 characters");
return;
}
}
private function validateemail1($em1){
if(!filter_var($em1,FILTER_VALIDATE_EMAIL)){
array_push($this ->errorArray , "Email is invalid");
return;
}
}
}
?>
This is not an answer, but rather a suggestion.
You are probably better keying your errors array with something like the field name to make error message retrieval easier.
I've adapted one of your validation methods so that it's possible to add multiple errors per field:
<?php
class AccountValidator
{
public $errors;
public function validateLastname($ln)
{
if(strlen($ln)>25 || strlen($ln)<2){
$this ->errors['lastname'][] =
"Your last name must have between 2 and 25 characters.";
return false;
}
}
}
$firstname = 'X';
$lastname = 'O';
$validator = new AccountValidator;
if($validator->validateLastname($lastname) === false)
{
echo
'<ul><li>',
implode('</li><li>', $validator->errors['lastname']),
'</li></ul>';
}
Output:
<ul><li>Your last name must have between 2 and 25 characters.</li></ul>
How to send $this->uname & $this->email to controller data to controller/ctrl_crud.php
create.php
<?php
include 'FullScreenLayout.php';
class index {
public $uname, $email;
public function get_data() {
if ( isset($_POST) ) {
$this->uname = $_POST['form_uname'];
$this->email = $_POST['form_email'];
}
}
public function createForm(){
$createHTML = <<<EOT
<form method="POST">
<div class="main_form">
<div class="md-form">
<input type="text" id="form_uname" name="form_uname" class="form-control" placeholder="User Name">
</div>
<div class="md-form">
<input type="text" id="form_email" name="form_email" class="form-control" placeholder="Email Address">
</div>
<button type="submit" class="btn btn-submit">Submit</button>
</div>
</form>
EOT;
return $createHTML;
}
}
$ObjFullScreenLayout = new FullScreenLayout();
$ObjIndex = new index();
$ObjIndex->get_data();
echo $ObjFullScreenLayout->header();
echo $ObjIndex->createForm();
echo $ObjFullScreenLayout->footer();
?>
controller/ctrl_crud.php
<?php
class ctrl_crud {
}
?>
Send those data to the constructor
include 'controller/ctrl_crud.php';
public function get_data() {
if ( isset($_POST) ) {
$this->uname = $_POST['form_uname'];
$this->email = $_POST['form_email'];
new ctrl_crud($this->uname, $this->email);
}
}
controller/ctrl_crud.php
class ctrl_crud {
function __construct($uname, $email){
// use uname and email here
}
}
Just add an action to your form that points to the page you want to send the data like so:
<form action="controller/ctrl_crud.php" method="post">
I'm working on a custom CMS using PHP OOP and this is actually my first project ever which is made with object oriented programming so I don't have that much of experience with it. Basically I have a class called Site.class.php which retrieves data from one of the tables in MySQL database and goes like this:
<?php
class Site
{
public $id,$site_name,$site_title,$site_url,$site_tags,$site_desc;
public function __construct()
{
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function getSite($name)
{
if(!empty($name))
{
$site = $this->db->prepare("select * from admins where site_name = ?");
$site->bindParam(1,$name);
$site->execute();
while($row = $site->fetch())
{
$this->id = $row['id'];
$this->site_name = $row['site_name'];
$this->site_title = $row['site_title'];
$this->site_url = $row['site_url'];
$this->site_tags = $row['site_tags'];
$this->site_desc = $row['site_desc'];
}
}
else
{
header("Location: maint/php/includes/errors/005.php");
exit();
}
}
public function getID()
{
return $this->id;
}
public function getSiteName()
{
return $this->site_name;
}
public function getSiteTitle()
{
return $this->site_title;
}
public function getSiteUrl()
{
return $this->site_url;
}
public function getSiteTags()
{
return $this->site_tags;
}
public function getSiteDesc()
{
return $this->site_desc;
}
}
?>
I have included this file at another file which is called settings.php and called it in this way:
$siteSet = new Site();
$siteSet->getSite("Daygostar");
Then I tried echoing out the variables like this:
<div class="box-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="usr">Site Name:</label>
<input type="text" class="form-control" id="usr" disabled='disabled' value="<?php echo $siteSet->getSiteName; ?>">
</div>
<div class="form-group">
<label for="usr">User URL:</label>
<input type="text" class="form-control" id="usr" disabled='disabled' value="<?php echo $siteSet->getSiteUrl; ?>">
</div>
</div>
</div>
</div>
But the problem is that whenever I call this file ,I receive this error message:
Undefined property: Site::$getSiteName
Undefined property: Site::$getSiteUrl
I don't know what's really going wrong because I have coded everything correctly! So if you know how to solve this question please let me know, I really appreciate that.. Thanks in advance.
Those are both methods. You need to add the () to the end of them to invoke the method.
<div class="box-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="usr">Site Name:</label>
<input type="text" class="form-control" id="usr" disabled='disabled' value="<?php echo $siteSet->getSiteName(); ?>">
</div>
<div class="form-group">
<label for="usr">User URL:</label>
<input type="text" class="form-control" id="usr" disabled='disabled' value="<?php echo $siteSet->getSiteUrl(); ?>">
</div>
</div>
</div>
</div>
Message show:
Product not updated!
Not updating through form. Rest of the code is working fine. Database is working fine. I think problem is in update query.
HTML form is in product.php and Controller is in product-controller.php and function code is in admin-model.php.
Select insert and delete query is working but update query is not working I don't understand why.
HTML Form
<form action="product-controller.php?type=update" method="post">
<input type="hidden" value="<?php echo $r["productid"]; ?>" name="productID" id="productID"/>
<div>
<label>Product Name</label>
<input type="text" value="<?php echo $r["product_name"]; ?>" name="productName" placeholder="Product Name">
</div>
<div>
<label>Product Price</label>
<input type="number" value="<?php echo $r["product_price"]; ?>" name="productPrice" placeholder="Product Price">
</div>
<div>
<label>Product Quantity</label>
<input type="number" value="<?php echo $r["product_quantity"]; ?>" name="productQuantity" placeholder="Product Quantity">
</div>
<div>
<label>Product Description</label>
<textarea name="productDesc"><?php echo $r["product_description"]; ?></textarea>
</div>
<div>
<button type="submit">Update Product</button>
</div>
</form>
Controller
<?php
include("admin-model.php");
if(isset($_GET["type"]))
{
$dbobj=new AdminModel;
if($_GET["type"]=="add")
{
$name=$_POST["productName"];
$price=$_POST["productPrice"];
$quantity=$_POST["productQuanity"];
$desc=$_POST["productDesc"];
$res=$dbobj->addProduct($name, $price, $quantity, $desc);
if($res>0)
{
header("Location: product.php?msg=sucess");
}
else
{
header("Location: product.php?msg=fail");
}
}
else if($_GET["type"]=="update")
{
$id=$_POST["productID"];
$name=$_POST["productName"];
$price=$_POST["productPrice"];
$quantity=$_POST["productQuantity"];
$desc=$_POST["productDesc"];
$res=$dbobj->updateProduct($id, $name, $price, $quantity, $desc);
if($res>0)
{
header("Location: product.php?msg=upsucess");
}
else
{
header("Location: product.php?msg=upfail");
}
}
else if($_GET["type"]=="del")
{
$id=$_GET["productID"];
$res=$dbobj->deleteProduct($id);
if($res>0)
{
header("Location: product.php?msg=delsucess");
}
else
{
header("Location: product.php?msg=delfail");
}
}
}
else
{
header("Location: product.php");
}
?>
Function Code
<?php
class AdminModel
{
var $con, $com;
var $res;
public function __construct()
{
$this->con=mysql_connect("localhost", "root", "");
mysql_select_db("mywebsitedb");
}
public function updateProduct($id, $name, $price, $quantity, $desc)
{
$this->com=mysql_query("update product set product_name='$name', product_price='$price', product_quantity='$quantity', product_description='$desc', where productid='$id'", $this->con);
return $this->com;
}
Please correct your update query as follows:
$this->com=mysql_query("update product set product_name='$name', product_price='$price', product_quantity='$quantity', product_description='$desc' where productid='$id'", $this->con);
This Query SQL is wrong syntax :
update product set product_name='$name', product_price='$price',
product_quantity='$quantity', product_description='$desc', where productid='$id'
-->
update product set product_name='$name', product_price='$price',
product_quantity='$quantity', product_description='$desc' where productid='$id'
I am working on a web back-end that will pull information into a form, and then when updated, will update the database with the new information. However, when I try to pull information previously stored in a class private variable, it throws me an error stating that the information is NULL. What am I doing wrong here?
<?php
class modify_racer
{
private $mysqli, $racer_id, $firstname,
$lastname, $banner, $bio;
public function error($code)
{
switch($code)
{
case 1:
echo '<p id="error"><b>Error:</b> Please fill out all fields!</p>';
modify_racer::send_form($this->firstname, $this->lastname, $this->banner, $this->bio);
break;
case 2:
echo '<p id="error"><b>Error:</b> Racer already exists!</p>';
break;
case 3:
echo '<p id="error"><b>Error:</b> Could not connect to MySQLi: ' . mysqli_error();
break;
}
}
public function send_form($modify = 1)
{
?>
<div id="form">
<h3>Edit Racer:</h3>
<form method="post" action="">
<label for="firstname">First Name: </label>
<input type="text" id="firstname" name="firstname"
placeholder="Racer's First Name"
value="<?php echo $this->firstname;?>" />
<br />
<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname"
placeholder="Racer's Last Name"
value="<?php echo $this->lastname;?>" />
<br />
<label for="banner">Banner Location: </label>
<input type="text" id="banner" name="banner"
placeholder="Racer's Banner Image Location:"
value="<?php echo $this->banner;?>" />
<br />
<label for="bio">Racer's Bio Info: </label>
<textarea rows="5" cols="50" id="bio" name="bio"
placeholder="Racer Statistics / Biography"
value=""><?php echo $this->bio;?></textarea>
<input type="submit" id="submit" name="modify" value="submit" />
</form>
</div>
<?php
}
public function get_racer($racerID)
{
$this->racer_id = $racerID;
$this->mysqli = new mysqli(MYSQLI_HOST,MYSQLI_USER,MYSQLI_PASS,MYSQLI_DATABASE)
or die(error(3));
$racer_info = "SELECT * FROM ArtecRacers WHERE RacerID=?";
$load_racer = $this->mysqli->prepare($racer_info);
$load_racer->bind_param('s', $racerID);
$load_racer->execute();
$load_racer->bind_result($this->racerID, $this->firstname, $this->lastname, $this->banner, $this->bio);
$load_racer->fetch();
modify_racer::send_form();
}
public function list_racers()
{
?>
<div id="form">
<h3>Select Racer:</h3>
<form method="post" action="">
<?php
$this->mysqli = new mysqli(MYSQLI_HOST,MYSQLI_USER,MYSQLI_PASS,MYSQLI_DATABASE)
or die(error(3));
$racer_list = "SELECT * FROM ArtecRacers";
$get_racers = $this->mysqli->query($racer_list);
while($list = $get_racers->fetch_array(MYSQLI_NUM))
{
echo '<input id="part" type="radio" name="editRacer" value="' . $list[0] . '"/>';
echo '<label for="part">' . $list[1] . ' ' . $list[2] . '</label><br />';
}
?>
<input type="submit" name="selectRacer" id="submit" value="Select Racer" />
</form>
</div>
<?php
}
function test2()
{
echo $this->firstname;
echo $this->lastname;
echo $this->racer_id;
}
}
$start = new modify_racer();
if(!isset($_POST['selectRacer']))
$start->list_racers();
if(isset($_POST['selectRacer']))
$start->get_racer($_POST['editRacer']);
$start->test2();
?>
Everything in the code works except at $start->test2(); all of the information pulled from the function test2() is blank, and I am not sure why... Any insights?
EDIT:
I changed the code to reflect the following on the bottom, and test2() still outputs the variables as NULL:
if(!isset($_POST['editRacer']))
$start->list_racers();
else
$start->get_racers($_POST['editRacer']);
$start->test2();
If you leave your code alone, you're going to have to pass both selectRacer and editRacer parameters into the page. My guess is that you might only want to pass the one, though. In which case, you'll want to change
if(isset($_POST['selectRacer']))
$start->get_racer($_POST['editRacer']);
into
if(isset($_POST['editRacer']))
$start->get_racer($_POST['editRacer']);
Also, if you want to pass these values in through the URL bar, you need to check $_GET, not $_POST.
And finally, everywhere that you are making method calls by executing modify_racer::my_method_here(), you should change that to $this->my_method_here(). The former is a static method call, meaning it's not actually associated with your object, meaning it can't touch those variables. For it to be able to access and change the variables, you'll need to call it through $this.