Jump to content

TOA

Members
  • Posts

    623
  • Joined

  • Last visited

Everything posted by TOA

  1. What you're describing is the basic functionality of a Learning Management System. They have content authoring programs that can embed quizzes and everything. The two I can think of off the top of my head are Lectura and Articulate. (Note, I have used Articulate in the past, but it's been a few years so their offerings may have changed.) If I remember correctly, you can host/run them from your own site. Don't re-invent the wheel if you don't have to. Hope that helps.
  2. Wordpress provides this to you in the loop as the_id() I think, but double check that. But to answer your question, here's how you'd do it: set meta_value = '5' where meta_key = '_price' AND post_id=(select post_id from postmeta where meta_key = '_sku' and meta_value = 'GF-1370') But use the post_id wordpress gives you, it's a much cleaner query
  3. I hate the way wordpress does tables, but I digress...You'll need to use the post_id to update the price, price is not actually in that record set meta_value = '5' where meta_key = '_price' AND post_id='4356'
  4. I believe what you want is CURLOPT_RETURNTRANSFER
  5. TOA

    Classes

    Global will work, but is not advised. Inject the dependency. Again, using globals is not advised.
  6. Delete line 24 and replace line 25 with this: $select = mysql_query("SELECT racun FROM clanovi_njihovi_racuni WHERE datum_unosa=CURDATE()"); curdate() is not a php function, it's a mysql function.
  7. Again I say, step back and start at the beginning. You're trying to run before you crawl. This has everything to get you started. http://www.php.net/manual/en/language.oop5.basic.php
  8. You're getting that error because the getName function is not defined in the user class. Sorry, I should have been clearer about that. You'll need to define that method and give it the needed functionality to return the author's name. And for what it's worth, author is a better name than user, it's clearer. You should really step back and learn the basics though. It seems like you might be getting ahead of yourself.
  9. Well besides the posts by ignace and KevinM1, which gave you alot of what you needed, Symphony has a pretty good article about moving from procedural to OOP, but I have to postface it with: OOP requires a different kind of thinking, so this will only get you so far into the OOP world. This is just a good place to get your feet wet. That being said, my first comment is: is a user a type of comment? Not in my mind, so you'd need a User object to pass into your comment object (dependency injection) which then gets assigned to the private $author property. Does that make sense? Always ask yourself 'is this a type of that' and if the answer is No, then it is a good place for a new class. So it would look like this $User = new User; $comment = new Comment($User); // now to get the author of the comment, we'd echo $comment->author; // although this would cause an error because the property is private. We'd need to change it to public or create getters/setters Now to expand on that, we can convert your procedural code to be like this: if ($_POST) { // create our data pieces $user = new User($_POST ['name']); $commentContent = $_POST ['commentcontent']; $comment = new Comment($user, $commentContent); //not quite sue what this means /** * To answer this question, this is writing the data to a file called comments.html */ $handle = fopen("comments.html","a"); fwrite($handle, "<b>" . $comment->author->getName() . "</b>:<br/>" . $comment->getContent() . ",<br/>"); fclose($handle); } BTW, this is just an example. Hope it helps you get started.
  10. Colons are just an alternate syntax : http://php.net/manual/en/control-structures.alternative-syntax.php The '? :' combo is called ternary operator and is essentially an inline if statement: http://php.net/manual/en/language.operators.comparison.php
  11. That shouldn't be the case if both thankyou.php and email_success.php exist. Try full php opening tags: <?php instead of <? It might be that your server doesn't recognize shorttags..
  12. instead of $name = $GET_POST['fullname']; $email = $GET_POST['email']; $message = $GET_POST['message']; try $name = $_POST['fullname']; $email = $_POST['email']; $message = $_POST['message']; And it would be a good idea to read up on GET and POST in the manual.
  13. It would be mysqli_num_rows($query), not $dbc. The call to num_rows is made to the result set. And by getting a COUNT(), it will always return a result so checking for num_rows won't work. Either change your select, or fetch the results and check for > 0 there.
  14. Use your page id instead of $user in the api call
  15. $teacher is referring to (my best guess) $object1. And you need to start your echo with the object your calling - ie: $object2->age, not $firstname->age $teacher = new person('Boring','12345','12345'); $student = new person('Me','Myself',99); echo $student->age;
  16. php uses .(dot) concatenation, not + echo "site_images/" . $id . "/" . $image; But I would do it in a more readable fashion; like this: $src = (empty($image)) ? "upload/your-photo.jpg" : "site_images/$id/$image"; <img src="<?php echo $src ?>" />
  17. I have to preface this with 'I'm not a PDO expert so if I miss-speak, please don't hold it against me.' The quick and simple explanation is that PDO gives you one universal interface for accessing your db. You call $pdo->query() and it knows that you have a MySQL server and so to use MySQL calls internally. That's an abstraction layer; you abstract the actual calls out of the client code and into an abstraction layer. Imagine you set everything up on a MySQL server. You then find out MySQL goes bankrupt and you need to replace it with a competitor. How long do you think it would take to go through all your code and replace all the calls to MySQL and also alter functionality for handling the results of those calls. With PDO or a similar layer, you would change the details in your PDO config and all your client code calls would remain the same. PDO Abstraction layer Don't leave questions unasked for fear of stupidity; It's stupid not to ask. If he's a real friend, he won't treat you like an idiot
  18. FYI: mysql is deprecated. You should switch to the mysqli extension, or better yet, to an abstraction layer such as PDO
  19. Updates are fine if you're updating. Insert's are for new rows. I think you're main error is that you never fire the query, but I've edited your code for several different things. 1. Added curly braces on line 4 - not necessarily needed in this case, but I consider it good practice so I threw them in there. 2. moved the else condition braces around the rest of the code to only run when there's a session; this was an assumption. 3. not sure what db engine your using in connect.php so I marked where you need to fire the query. 4. added indentation I didn't test it but it should be good. <?php include 'connect.php'; include 'main.php'; if(!isset($_SESSION['id'])) { // added curly braces echo "You need to login to view this page"; } else { // added indents $id = $_SESSION['id']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $motto = $_POST['motto']; $bio = $_POST['bio']; if(empty($firstname) || empty($lastname) || empty($motto) || empty($bio)){ echo "You didn't fill out any fields."; } else if (strlen($motto) < 5) { echo "Your motto must be more than 5 characters."; } $sql="UPDATE users SET firstname='$firstname', lastname='$lastname', bio='$bio', motto='$motto' WHERE id='$id'"; // you never actually fire this query...do so here } // moved this to wrap the code ?>
  20. I would normally agree, but there's great potential with the historical data this would generate. You could see what you showed on Jan 24th for example. OP: I'd do it with a cron and a simple query on the page. CREATE TABLE `videos` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `url` varchar(255) NOT NULL, // assuming these are actually stored in a file structure PRIMARY KEY (`id`) ) CREATE TABLE `video_views` ( `id` int(11) NOT NULL AUTO_INCREMENT, `vid` varchar(50) NOT NULL, // FK from video table `date` timestamp NOT NULL, PRIMARY KEY (`id`) ) // CRON // query for 3 videos from videos table - this is where you'd add your additional business rules for which videos to display ie: per week, per month, etc. // insert them into video_views table with a timestamp/date // PAGE // query for all videos with today's date // show them
  21. All this is done with CSS. Rounded corners Hover state (I would not normally send you to w3schools, but not even they can get this wrong)
  22. By what you're saying, that all you did was change the name of a variable, there's no way it wouldn't work by changing it back. I thought about a reserved word clash but you said changing it back doesn't make it work again. It can therefore NOT be the name and you HAD to have done something else. That's logic. I'm sorry you disagree. Maybe if you post more code, it would help...
  23. Then that's not what broke your script. You had to have done something else
  24. Try changing the name back to email2 and see if it goes back to working..
  25. Forgot a ; on the line before
×
×
  • 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.