Jump to content

kartul

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

Everything posted by kartul

  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.
  15. Hello, I'm having a jQuery problem. I'm trying to create ajax pagination but there is one big flaw. Everything works like it should but the ajax works only one time. Example. I go to the page, click on next (or any of the page numbers or last etc.) it loads the contents with ajax, displays it, everything's fine. But when I click again on some pagination link (next, any of the numbers etc.) it loads the page normal way. and then the it starts all over again, one time the links make ajax call, the other time they wont. Heres the code: $(document).ready(function() { $("#pagination a").click(function(e) { e.preventDefault(); $("#encodes").fadeOut().delay(400); $.ajax({ type: "GET", url: this + "&pagination=true&ajax=true", dataType: "json", success: function(ms) { $("#encodes").empty().append(ms.content); $("#pagination").empty().append(ms.pagination); $("#encodes").fadeIn(); } }); }); }); How do fix this?
  16. 1st. There's probably mysql error in that query, add mysql error function to check that. 2nd should disappear when you fix first one.
  17. Hello. The idea: Have a page with multiple forms. Each form has a two buttons - Yes and No. Form is submitted with one of the buttons and the process page takes care of that. The form disappears, text is displayed that everything went fine and after 5 seconds the text is gone, leaving me with nothing. If something went wrong - with the ajax request or the process page returns false, it does something like adds red background. What I have: Page with multiple forms, all with the same class (ajaxform), one input field (no id or class) and two buttons, both with the same class (button). I used jQuery Form Plugin (http://jquery.malsup.com/form/) and the form is submitted successfully, no page reload. I used the ajaxform as selector. ($('ajaxform').ajaxForm()). But I did not managed to get the submitted form to hide or to display any messages. I tried $(this).hide(); on success but all that did was broke the thing and the form was submitted with page refresh. Using $.ajax function, the serialize doesn't seem to work. url = 'tools.php?action=approve'; data = $(this).serialize(); // i used ('.ajaxform') instead of (this) too. alert(url + data); returns only url part. Help I need(?): I figured that I need id instead of class in form but how do I do that? Then I would need new ajax submit function for every form I have. Or when using the form plugin, how can I get the submitted form to hide and display something there. I figured that (this) should work cause, well this is the current thing that got changed. Code I have: // it's all in while loop, the row is array from database. echo '<form class="ajaxform" action="' . BASE_URL . 'tools.php?action=approve&id=' . $row['id'] . '" method="POST"> <b>ID:</b> <input type="text" value="' . $row['id'] . '" disabled size="' . (strlen($row['id']) + 1) . '" /> <button type="submit" name="approve" value="yes" class="button">Yes</button> <button type="submit" name="approve" value="no" class="button">No</button> </form>'; jQuery code: $('.button').click(function() { $('.ajaxform').submit(function() { /*$.ajax({ });*/ url = 'tools.php?action=approve-secrets'; data = $(this).serialize(); alert(url + data); }); }); Only display the url part. $('.button').click(function() { $('.ajaxform').submit(); }); Doesn't work. $(".button").click(function() { $(".ajaxform").submit(function() { $.ajax({ url: '<?php echo BASE_URL; ?>tools.php?action=approve', type: 'GET', data: $('.ajaxform').serialize(), success: function() { $(this).hide(); } }); }); }); goes to tools.php?action= ...etc. &id=5 to the form url. var options = { success : function() { $(this).hide(); } } $('.ajaxform').ajaxForm(options); submits the form but doesn't hide it. Any ideas?
  18. Well, you have to change the displaying errors code too. // $errors['form1'][0] = 'asda'; $errors['form1'][1] = 'aasdsda'; $errors['form1'][2] = 'asddwa'; $errors['form2'][0] = 'asdwdwwwwwa'; $errors['form2'][1] = 'a2dafsda'; $errors['form2'][2] = 'asiuuuuda'; foreach($errors['form1'] as $error) { echo $error . "<br />"; }
  19. use print_r and var_dump to debug the variables.
  20. How about you make multi-dimensional array? $error[form1][error1] $error[form2][error1]
  21. From error I can see that field name something does not exist. Where did you get something anyway? I can only see login, access_level, first and lastname options.
  22. change first line to: <?php include('thedatabase.php'); you were missing ' at the start
  23. WOW. I added /test/ into my pagination script and it all works perfect! Thank You so much.!!
  24. Damit! I had a problem and I solved it but got another problem. Now both problems are there. Damit, my mistake. I have the styles, js and images fixed. I added the full url there. They work now fine. The real problem what I'm now facing is the pagination (content split between pages) urls. Currently I have following line: RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [QSA,NC,L] The pagination works, content get's splited up between pages but the url is messed up. first page get's served as myhost.com/test/page/2, next url is myhost.com/test/page/page/3 (it works tho, right content is shown), next one again, one more page there (myhost.com/test/page/page/page/3). if I go back, it still adds another page/ there. Now, my question is, how can I get rid of the page/'s there and only show one? Again, I apologies for the wrong info in first post.
×
×
  • 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.