Jump to content

kartul

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

About kartul

  • Birthday 05/13/1992

Contact Methods

  • MSN
    k_sks@hotmail.com
  • Website URL
    http://www.suppersoccer.pri.ee

Profile Information

  • Gender
    Male
  • Location
    Estonia

kartul's Achievements

Member

Member (2/5)

0

Reputation

  1. Yes because when I replace $class with test, it works. // edit. And I mean in the line $this->loaded_classes[$class] = new test();
  2. Hey all Creating new class by variable should work, atleast in php manual says so but why it isn't working here? Using php 5.3.7. Error it says is can't find class called 'test'. It is there and if I replace $class with test the it works. And $class is equal to test. function load_class($path, $class) { $class = strtolower($class); if( isset( $this->loaded_classes[$class] ) ) { return $this->loaded_classes[$class]; } else { #include $path . 'test.php'; #include './' . $class . '.php'; #debug_backtrace($class); #$s = new $class; include $path . $class . '.php'; #eval('self::$loaded_classes['.$class.'] = new '.strtolower($class).'();'); $this->loaded_classes[$class] = new $class(); echo 'ok'; return $this->loaded_classes[$class]; } }
  3. Maybe ... Anyway, I just went with natural join and left the anonymous data empty. Right now i just display anonymous instead of the name that anonymous person wrote. The reason I use anonymous table is when one user posts many times under same details, I'll give him a change to register with the username he used if it's not already in use. Also to keep track on visitors on page maybe. Thanks for the reply!
  4. One thing to notice, You are using very long index keys, maximum length of GET is 255. Maybe You are exceeding that limit and therefor the data is missing. Try using POST or shorten Your index keys. Also, name (html attribute) == index key (php $_GET[indexkey]! Otherwise it wont work.
  5. ok so i've deleted all data and tried reentering is, but still the same error came out. do u mean that i should add foreign keys in the company_id first before prompting the data from php to mysql? Nope. You did right. I don't know then, it worked for me tho ...
  6. Hello all. I have 5 tables: posts, users, users_to_posts, anonymous, anonymous_to_posts. Now what I try to accomplice here is when post is submitted, it's content is entered into posts table, if it's submitted by anonymous the username and email is entered into anonymous table and anonymous_id and post_id are inserted into anonymous_to_posts table. And if user is logged in, basically same data will be entered into users and users_to_posts table. Now, I want to display the posts ordered by added time and show user/anonymous information below it. Now, I don't know how do make the query. I've tried left joins and natural joins. Now, natural joins get the data but only for one - anonymous or user. I've attached database design below. So, how to do it? I don't expect working query here cause it's quite hard but some link that explains multible joins or anything. [attachment deleted by admin]
  7. Wow that did the trick! To my understanding, the ^ means beginning of a string. But I guess in some context it's not, lol. Thanks a lot man! Yes it does, when it's not in the brackets. I'm not sure of the technical terms, but here is a good tutorial: http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax How could I have missed it. Thank you!
  8. Wow that did the trick! To my understanding, the ^ means beginning of a string. But I guess in some context it's not, lol. Thanks a lot man!
  9. Now, the error is gone, thank you! *sits and thinks for a minute* but it doesn't really solve what I was hoping for... I have new question now, how do I get that if username contains characters other than what's in this regexpression, the if statement fails? Is there are some kind of function that I doesn't know of? Or what is the right way to do it?
  10. With what you need help with? Some error, warning, something not showing up?
  11. Hello all! I'm trying to create registration and login system for my page and I want usernames contain only a-zA-Z0-9._- characters. So I use preg_match in if statement to check that (is this right way?) but it gives me an error. I googled but no answer for me. Here is the error: And the if statement that produces the error message: $username = (isset($_POST['username']) && strlen($_POST['username']) <= 25 && strlen($_POST['username']) >= 2 && preg_match('([a-zA-Z0-9._- ]+)', $_POST['username'])) ? $filter->process($_POST['username']) // just returns mysql safe string : false;
  12. Hey all I want to make that when I click on login, the login div appears (and if registration div is visible, hide it first) and vise-versa. here is my code so far: <script> $(document).ready(function() { $("#tLogin").click(function() { $("#login").slideToggle("slow"); }); $("#tRegister").click(function() { $("#register").slideToggle("slow"); }); }); </script> <div id="pHeader"> <div id="login"> <form action="index.php" method="POST"> <p> <label for="username">Username</label> <input type="text" name="username" id="username"> </p> <p> <label for="password">Password</label> <input type="password" name="password" id="password"> </p> <p> <input type="submit" name="login"> </p> </form> </div> <div id="register"> <form action="index.php" method="POST"> <p> <label for="username">Username</label> <input type="text" name="username" id="username"> </p> <p> <label for="password">Password</label> <input type="password" name="password" id="password"> </p> <p> <label for="password">Password</label> <input type="password" name="passwordCheck" id="passwordCheck"> </p> <p> <label for="email">E-mail</label> <input type="email" name="email" id="email"> </p> <p> <input type="submit" name="register"> </p> </form> </div>
  13. function at_name($content) { $pattern = '/\@([a-zA-Z0-9._-]+)/'; $replace = '<a href="'. BASE_URL . 'u/\1">@\1</a> '; return preg_replace($pattern, $replace, $content); }
  14. Hello all. I have never used transactions before and I'm building a website right now and trying to use one. Now, the question here is do I use it right? I have 3 tables, posts, users and users_to_posts which holds all ids (id, user_id, post_id). Now as I need to get the last insert id from database, I need to lock tables cause when two people post at the same time, it might get all mixed up. Now I use the lock tables statement first time. Anyway, all this story aside, the question. Do I use this block right? if(isset($_SESSION['uID'], $_SESSION['username'])) { // User try { $dbh->beginTransaction(); $stmt = $dbh->exec('LOCK TABLES `posts` WRITE, `users_to_posts` WRITE'); $insert = $dbh->prepare('INSERT INTO `posts` (`content`) VALUES (:content)'); $insert->bindParam(':content', $post, PDO::PARAM_STR, 350); $insert->execute(); $jointbl = $dbh->prepare('INSERT INTO `users_to_posts` (`user_id`, `post_id`) VALUES (:uID, :pID)'); $jointbl->bindParam(':uID', $_SESSION['uID'], PDO::PARAM_INT, 11); $jointbl->bindParam(':pID', $dbh->lastInsertId(), PDO::PARAM_INT, 11); $jointbl->execute(); $unlock = $dbh->exec('UNLOCK TABLES'); $dbh->commit(); } catch(PDOException $e) { echo $e->getMessage(); } } Oh, just in case. There are no errors, it works. I just want to know if it's the right way to use it.
×
×
  • 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.