Jump to content

macross

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

macross's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks call_user_func_array() works perfectly!
  2. I would like it to function like in codeigniter when passing Ids to methods you can do this: class Home extends Controller{ public function __construct(){ } public function index($id1, $id2){ echo $id1; echo $id2; } }
  3. So this is an example how i would like to get values from array inside a function. ( Note that array is an unknown size.. It might be empty or it might contain 3 keys) $data = array(1=>"hello", 2=>"welcome"); function doSomething($value1, $value2){ //Do something } doSomething($data) How can i achieve such thing?
  4. Thanks i will look into those books.
  5. Is there any decent eBook about building content management system from scratch which would use front-controller design pattern? Everything i find on the internet it's just plain old html/php smashup. I have searched and found only one book which is exactly what i wanted it's called "CMS Design Using PHP and jQuery", but as soon as i started reading it became clear that it's horrible (Bad programming practices)... Variable names starts with one letter like $j, $r directory names also with one letter, loops nested 4 levels up while you can achieve same thing with one loop... It's really hard to understand what’s happening when all I can see is spaghetti code. So maybe someone could point me to a decent eBook? I hope this is correct section for my question if not please move it.
  6. Solved my problem using implode() function.
  7. So i have an url routing class set up. I wan to call method via url so it would look something like this: http://www.mysite.com/index.php/Class/Method/Parameter. I was able to instantiate class like this: $controller = new $this->UrlPath[0]; But i can't call method the same way $controller->$this->UrlPath[1](); Is there a way to call method with an array?
  8. DreamerX i assume you know what is OOP, if thats the case, then check out this tutorial http://net.tutsplus.com/tutorials/php/create-your-first-tiny-mvc-boilerplate-with-php/
  9. Finally found out what was wrong so problem solved!
  10. So the correct way of calling a non static method would be $settings = $this->get_settings();? Because i get same error if i where using base::get_settings() or $this->get_settings();
  11. So i am currently coding database connection class and i have encountered very strange behavior from my script. base.class.php: <?php class base{ private $settings; function get_settings(){ $settings["dbhost"] = 'localhost'; $settings["dbuser"] = '*****'; $settings["dbpass"] = '*****'; $settings["dbname"] = 'core'; return $settings; } } ?> database.class.php <?php require_once 'base.class.php'; class database extends base{ private $query_now; private $link; public function __construct(){ $settings = base::get_settings(); $dbhost = $settings["dbhost"]; $dbuser = $settings["dbuser"]; $dbpass = $settings["dbpass"]; $dbname = $settings["dbname"]; $this->link = mysql_connect($dbhost, $dbname, $dbpass) or die ("Could not connect to the mysql database"); mysql_select_db($dbname, $this->link) or die ("Could not select the database"); } function query($query){ $this->query_now = $query; return mysql_query($query, $this->link); } function getArray($result){ return mysql_fetch_array($result); } } ?> When i try to create an instance of database class, i get mysql_connect error. I have tried to echo my array and it seems that correct information is being passed over. Now the strange thing is if i remove my password from the base class i don't get a mysql_connect error but this time instead i get "Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'core'@'localhost' (using password: YES) " In case you are wondering, does my mysql database user has a password, the answer is: yes for sure... (Also i have tried to setup a simple script for connecting to my database and everything worked fine) So any ideas?
  12. Thanks for pointing that out. I will definitely change some stuff around.
  13. Thank you! This is exactly what i wanted.
  14. Functions.php <?php include 'Database.php'; //New user registration function register_user($username, $password, $email){ //Prevent mysql injection TODO: Implement "stripslashes" $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $email = mysql_real_escape_string($_POST['email']); //Check if passwords where correct if ($_POST['password'] != $_POST['confirm']){ //If not send error message $reg_error = "Passwords did not match!"; include 'regform.php'; exit; }else if ($username =='' || $password =='' || $email ==''){ //Check if all fields are filled $reg_error = "Please fill in all fields!"; include 'regform.php'; exit; } //Check is the username already in the database $check = mysql_query("SELECT * FROM users WHERE username = '$username'"); $result = mysql_num_rows($check); //Check if the email is already in the database $check2 = mysql_query("SELECT * FROM users WHERE email = '$email'"); $result2 = mysql_num_rows($check2); //If username exists throw and error if($result > 0){ $reg_error = "This username is already taken!"; include 'regform.php'; exit; } //If email exists throw an error else if ($result2 > 0){ $reg_error = "This email is already taken!"; include 'regform.php'; exit; } //encrypt password with md5 $encrypt = md5($password); //Register user mysql_query("INSERT INTO users (username, password, email) VALUES ('$username', '$encrypt', '$email')"); } //Login user function log_user($username, $password){ session_start(); //Prevent mysql injection $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $decrypt = md5($password); //Do a query against the DB $checking = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$decrypt'"); $count = mysql_num_rows($checking); //User found set session if ($count == 1){ $_SESSION['logged'] = 1; header("location: main.php"); } //User not found else{ $log_error = "Incorect username or password"; include 'login.php'; exit; } } ?> Regform.php <?php include 'functions.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>User registration</title> </head> <body> <form action="regform.php" method="POST"> <b>Username:</b><input type="text" name="username"/><br/> <b>Password:</b><input type="password" name="password"/><br/> <b>Confirm password:</b><input type="password" name="confirm"/><br/> <b>Email:</b><input type="text" name="email"/><br/> <input type="submit" value="submit"/> </form> <?php if (isset($reg_error)){ echo $reg_error; } ?> <a href="login.php">Or login</a> </body> </html> <?php if (isset($_POST['Submit'])){ register_user($username, $password, $email); } ?> So as you can see i am developing a registration / login script. I've had looked at numerous tutorials for registration and login scripts but all of them uses external .php file for data handling (action="whateverfile.php"). And i want to do it all in one file (regform.php). So i've made two functions one for login and other for registration but if i try to call my function in regform.php nothing happends... So what im doing wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.