[PHP]Help [OOP]

Status
Not open for further replies.

Mac

New Member
Feb 9, 2011
111
2
Well , i helped powahcoder with a motto change system , and i wanted to make it OOP so i made it! Anyways i don't have MySQL in my webhost so when i am testing it, it's giving me mysql errors (that's clear!) but i want you to check my code if everything is good , and if there are any other errors (yeah , in PHP doesn't show all errors in 1 time).
My opinion is yes my code is clear.
Anyways here's my code :
PHP:
<?php
mysql_connect("host", "root", "pass"); # Edit this!
mysql_select_db("dbname"); # Edit this!
class Motto {
	public $query_cont = "WHERE username = '".$_SESSION["username"]."'";
	public static $actual_motto = mysql_query("SELECT motto FROM users ".$query_cont."");
	public static $new_motto = strip_tags($_POST["motto"]);
	public $isSubmited = $_POST["submit"];
	public function startSystem() {
		if($this->isSubmited):
			if(isset($this->new_motto)):
				Mysql_query("UPDATE users SET motto = '".$this->new_motto."'".$query_cont."");
				echo "Your motto is changed to ".$this->new_motto;
			else:
				mysql_query("UPDATE users SET motto = 'No motto entered!'".$query_cont."");
				echo "Your motto is changed to No motto entered!";
			endif;
		else:
?>
			<form method='post'>
			<b>Please write your new motto : </b> <input type='text' name='motto'> <br />
			<input type='submit' name='submit' value='Change my motto!'>
			</form>
<?php
		endif;
	}
}
$motto = new Motto;
$motto->startSystem();
?>
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
This is a waste of time, making a whole class for it will only make it slower.
Anyways, everything seems 'bout right, cba to test it.
 

Mac

New Member
Feb 9, 2011
111
2
@Kryptos {
Yeah , i know i just wanted to make it OOP , and yeah i never seen a people checking 34-line code in less than 1 minute! no offence .
}
 

Livar

Now 35% cooler!
Oct 15, 2010
846
86
You don't need this really, use the simple way, my way (made for uberCMS):

Code:
<?php 
			if (strlen($motto) == 0)
			{
				$motto = "";
			}	if (isset($_POST['motto']))
{
	$motto = $_POST['motto'];
	


{

	dbquery("UPDATE users SET motto = '" . $motto . "' WHERE username = '" . USER_NAME . "'");
echo '  <form method="post">
							<input type="hidden" name="token" value="SEC-467_0439d6b4d2982cb820664c100db82df61" />
							<input type="text" name="motto" value="' . $motto . '" style="margin-right: 5px; width: 175px;" />
							<input type="submit" value="Save" name="hidden_motto" style="width: 65px;" />
						</form>';


}   } else { echo '  <form method="post">
							<input type="hidden" name="token" value="SEC-467_0439d6b4d2982cb820664c100db82df61" />
							<input type="text" name="motto" value="' . $motto . '" style="margin-right: 5px; width: 175px;" />
							<input type="submit" value="Save" name="hidden_motto" style="width: 65px;" />
						</form>';  }?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Powahcoder and Kryptos are right, it's not worth putting it in it's own PHP class when it can be done within 10 lines, it just slows down the whole project.

As for the code, it looks good and well structured, but there is really no point in putting it in its own class :p
 

Mac

New Member
Feb 9, 2011
111
2
Yeah , i just wanted to make it OOP . So code is right ? Thank you for testing!

Please close thread!
 
Status
Not open for further replies.

Users who are viewing this thread

Top