Everything posted by gsingh85
-
create php class for comment box
Ok so should I put the __construct function into the comment class? So I could have public function__construc() { $this ->author = ; // what would I put here? I want to maintain the code I have created without doing any major re-writes.
-
create php class for comment box
Well I have tried to do it without using classes and objects and it works fine but I want to now re-do it using OOP. It's just for a learning excerise which is why it's simple. With regards to this code: function __construct($arg_one,$arg_two) { $this->arg_one = $someValueYouWant; $this->arg_two = $anotherValue; } where would I put this function. Is it in the comments or user class? It's done now the ways it's done so once this is complete I will adjust it for the one class. To avoid complications I will leave it as two classes for now. Anyway, where you have put arg_one, arg_two what would these be in the context of my code? Also in the Comment class the two properties have gone. Are you able to do it so we can keep these properties and have objects of the class?
-
create php class for comment box
Yes I have included everything. That's the complete code. The reason why I have left the user class empty is because I'm not sure what to put in it. Shall I had this function into the Comment class: public function __construct
-
create php class for comment box
Ok I've literally been at this for about 2 hours. After some tweaks I've managed to get this error: Fatal error: Call to a member function getName() on a non-object in C:\xampp\htdocs\tutorials\basiccomment\index.php on line 34 This is because of this code: $comment->author->getName() and $comment->getContent(). If I change to this: $comment->author & $comment->comment Then I don't get the above "fatal error" instead it posts empty "name" and "commentcontent". If fact it posts ":;" on the html file. I think I'm starting to understand the theory and the logic behind it but I've not got it to work so I still haven't fully grasped it. I've been switching between recommended links, sites and tutorials but they do things slightly different from each other so it's hard to fit it into a real world application. I know I've done it wrong because it's not posting anything but I'm not sure what I need to do to put it right. I've been doing some changes here and there but I've still not got it to work. I think I missing a function somewhere but I'll post the code in full if anyone is kind enough to offer me any information. <?php class Comment { public $author; public $comment; } class user { } $User = new User; $comment = new Comment($User); // now to get the author of the comment, we'd echo $comment->author; 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 . "</b>:<br/>" . $comment->comment . ",<br/>"); fclose($handle); } ?> <html> <body> <form action = "" method = "POST"> Comments: <textarea rows = "10" cols = "30" name = "commentcontent"></textarea><br/> name: <input type = "text" name = "name"<br/> <input type = "submit" value = "post!"><br/> </form> <?php include "comments.html"; ?> </body> </html>
-
create php class for comment box
Thanks for your reply. Have I created the class and objects correctly?
-
create php class for comment box
Hi Every. Over the last few days I've been working on my very basic comment box programme. I've purposly kept it basic so I can follow it. I managed to make the programme work using a tutorial without any kind of classes or objects but now I want to create the code in oop style. I've created a class which I think is right and within that class I have created 2 variables within it. I have also created 2 objects of that class however I don't think I've done it right. Can someone please have a look at it and point out where I need to make the amendments. <?php class Comment { private $author; private $comment; } $username = new comment (); $usercomment = new comment (); //if the form has been submitted then we want to execute some code in the brackets if ($_POST) { //below we have defined are variables. $username = $_POST ['name']; $usercomment = $_POST ['commentcontent']; //not quite sue what this means $handle = fopen("comments.html","a"); fwrite($handle, "<b>" . $username . "</b>:<br/>" . $usercomment . ",<br/>"); fclose($handle); } ?> <html> <body> <form action = "" method = "POST"> Comments: <textarea rows = "10" cols = "30" name = "commentcontent"></textarea><br/> name: <input type = "text" name = "name"<br/> <input type = "submit" value = "post!"><br/> </form> <?php include "comments.html"; ?> </body> </html>
-
Help with PHP messages
@citypaul - ok thats no problem. i will to see more posts from you about this video. thanks a lot.
-
Creating JQUERY effects using software
Yes I think I will do just that. It's not that difficult to learn JQ. It seems to be a collection of effects for people to use very much like CSS.
-
Creating JQUERY effects using software
I want to use Jquery for the sake of variety just so I can show off my skills in a job interview if nothing else. How about if I use Adobe Animate? Would I be able to create jquery code on there and place the code in a html script?
-
Creating JQUERY effects using software
Yes exactly. I'll give you an example and this is just an example. I want to create a gallery for one of my websites but I don't know exactly how I want the effects/animation to be so I want to expirment.
-
Creating JQUERY effects using software
I am trying to create some animation/special effects on my website and I want to use JQUERY. The thing is I want to be able to experiment because I don't really know what I want until I play around with it. Is there a way I can create jquery animation using software? For example, if I want to design a certain layout for a fashion company I could experiment using Photoshop, get the layout, colour scheme and so on but I can't see a way of doing that with Jquery.
-
Help with PHP messages
I have to say I'm really disappointed to hear you say this. I took a lot of time to learn this code from a developer who I thought was an expert in php. As someone new to php I can’t really tell the difference between good php code and bad php code. My general rule of thumb when trying to learn php code is, is it flexible? Is it lightweight? Does it work? If the answer is yes to all 3 then I will learn it and keep it for reference and re-use it. To hear you say the code is badly written and outdated is quite disheartening. This is code for creating a newsletter and I have tested it and the answer is a “yes” to the above 3 questions. If the code is so bad would you be able to post an equivalent newsletter code that is written with OOP in mind and I will study that and compare it to the “badly” written code. I can then use your code as a reference to good practise. Thanks in advance.
-
Help with PHP messages
Any more ideas?
-
Positioning validation messages in a certain place
Sorry for the late response. Yes that has worked. Thanks very much, that's a really big help.
-
Help with PHP messages
Thanks for your reply. Adding those lines doesn't work because when I load the page the boxes dissappear so I can't type anything in. Any suggestions? By the way. I don't want the messages to display on a different page I would like to keep everything on the one, same page.
-
Help with PHP messages
I have a simple newsletter sign up script that I'm using. I built it using a tutorial and because it's simple and basic I'm able to tweak it here and there as and when I need to. There are some messages such as "?? is already on the system" and "please enter an email address". All these work fine however when I display certain messages such as "is already on the sytem" or "you have been added sucessfully" I want the text boxes to disappear. I've been looking online and I haven't found anything which is most likely because I don't know the correct terminology of what I'm looking to do. I only what the boxes to dissappear when certain messages are display. Can someone please help me with this or direct me to a tutorial. Thanks in advance. Here is the script: <?php $name = ""; $email = ""; $msg_to_user = ""; if (isset($_POST['name']) && $_POST['name'] != "") { include_once "connect_to_mysql.php"; // Be sure to filter this data to deter SQL injection, filter before querying database $name = $_POST['name']; $email = $_POST['email']; $sql = mysql_query("SELECT * FROM newsletter WHERE email='$email'"); $numRows = mysql_num_rows($sql); if (!$email) { $msg_to_user = '<br /><br /><h4 class="header">Please type an email address ' . $name . '.</h4>'; } else if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $msg_to_user = '<br /><br /><h4><font color="FF0000">invalid email address.</font></h4>'; } else if ($numRows > 0) { $msg_to_user = '<br /><br /><h4><font color="FF0000">' . $email . ' is already in the system.</font></h4>'; } else { $sql_insert = mysql_query("INSERT INTO newsletter (name, email, dateTime) VALUES('$name','$email',now() )") or die (mysql_error()); $msg_to_user = '<br /><br /><h4>Thanks ' . $name . ', you have been added successfully.</h4>'; $name = ""; $email = ""; } } ?> </div> <html> <head> <style> .header { color:#D2691E; background-color: #000000; } </style> <title>Subscribe to Our Newsletter</title> </head> <body> <form style="width:440px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset style="text-align:left; padding:24px;"> <legend>Subscribe to Our Newsletter </legend> <br /> Name:<br /> <input name="name" type="text" maxlength="36" value="<?php echo $name; ?>" /><br /> Email:<br /> <input name="email" type="text" maxlength="36" value="<?php echo $email; ?>" /><br /><br /> <input name="mySubmitBtn" type="submit" value="Submit"> <?php echo $msg_to_user; ?> </fieldset> </form> </body> </html>
-
Positioning validation messages in a certain place
Thanks for your reply. I'm not quite sure what you mean by this. This still doesn't allow me to position the error message in a certain place or I may have miss understood. Can you please clarify, thanks. @sash_oo7 I haven't tried that yet but even if I did that still doesn't allow me to place the message in a certain place in or out of the form. Anymore suggestions? Like I said I have tried using a div but no joy. This seems the easier way to do it but it doesn't work.
-
Contact Me forms
That's fantastic thanks very much. I can now move on and get building my contact and membership forms.
-
Contact Me forms
I see so other than php what other scripts could be used to send an email via a contact form?
-
Contact Me forms
Thanks for your replies. Ok so other than php what other processing languages could be used? How about Javascript?
-
Contact Me forms
At first glance creating a "Contact Me" form seems pretty straightforward however when I look at some information on it, it looks like most people create these forms using php. I would have thought you could send the message using the html created form without having to use php because, as far as I know, there is no reason to connect it to the server or to a database. All the form is there to do is take additional details such as Name, email address, the type of query etc, the comments and the send button. So as far as I can see here there shouldn't be any need to connect the form to the server/database and therefore there is no need to use php yet most people do so I was just wondering why that was. Is it because in order to actuall "send" an email using the form php is a must? If it's not a requirement I would probably not use php but as most people use it when creating 'contact me' forms are there any benefits in using php?
-
Positioning validation messages in a certain place
I've been trying to work this out for hours without any success. Basically I'm trying to place the validation messages in a certain place. I want the flexibility of placing the error messages anywhere I want on the page. For example, at the moment if no-one fills in the 'email address' field an error message will come up saying "please type in an email address". By default the message comes up below and within the newsletter form. I want to place the message outside and above the newsletter form, however I don't want to stop there. I want to be able to place the message anywhere I want, e.g. 300px from the right of the form, 400px margin-top etc. I'm thinking ahead because when it comes to the real thing I may have all kinds of texts and images on a page and I want to be able to work around them. I have tried different things but nothing has worked. I've tried putting the html form and php code in a div id but still no joy. Any help would be much appreciated. Here is the code: <?php $name = ""; $email = ""; $msg_to_user = ""; if (isset($_POST['name']) && $_POST['name'] != "") { include_once "connect_to_mysql.php"; // Be sure to filter this data to deter SQL injection, filter before querying database $name = $_POST['name']; $email = $_POST['email']; $sql = mysql_query("SELECT * FROM newsletter WHERE email='$email'"); $numRows = mysql_num_rows($sql); if (!$email) { $msg_to_user = '<br /><br /><h4 class="header">Please type an email address ' . $name . '.</h4>'; } else if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $msg_to_user = '<br /><br /><h4><font color="FF0000">invalid email address.</font></h4>'; } else if ($numRows > 0) { $msg_to_user = '<br /><br /><h4><font color="FF0000">' . $email . ' is already in the system.</font></h4>'; } else { $sql_insert = mysql_query("INSERT INTO newsletter (name, email, dateTime) VALUES('$name','$email',now() )") or die (mysql_error()); $msg_to_user = '<br /><br /><h4>Thanks ' . $name . ', you have been added successfully.</h4>'; $name = ""; $email = ""; } } ?> </div> <html> <head> <style> .header { color:#D2691E; background-color: #000000; } </style> <title>Subscribe to Our Newsletter</title> </head> <body> <form style="width:440px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset style="text-align:left; padding:24px;"> <legend>Subscribe to Our Newsletter </legend> <br /> Name:<br /> <input name="name" type="text" maxlength="36" value="<?php echo $name; ?>" /><br /> Email:<br /> <input name="email" type="text" maxlength="36" value="<?php echo $email; ?>" /><br /><br /> <input name="mySubmitBtn" type="submit" value="Submit"> <?php echo $msg_to_user; ?> </fieldset> </form> </body> </html>
-
PHP form validation
Ah that makes sense. A handy little tool then. Thanks for your help.
-
PHP form validation
I'm looking at a php/html script that is like a comments form. What I'll be doing is adding some drop down menus in it and connecting it to database so I can use the form to collate data from website visitors. I've looked at a lot of these kind of forms and many of them have a few different ways of doing their validation. When I look at this script I like it because it seems to be quite flexible so it can be manipulated quite easy but I'm struggling to find out where the code is to say where the validation message should be displayed. By default if I press the submit button without filling in certain fields such as "email address" the validation message will show on the right hand side of the "email address" box however I can't see the code that tells the validation message to display the message on that part of the page. Same goes for the "name" box. There is nothing there that I can see to say the "please enter your name" message must display on the right side of the "name" box. There are no divs or columns so I'm a little confused how it automatically knows where to display the message. I can see there is an instruction to change the colour of these messages but there is nothing about the positioning. Can anyone point me towards where I should be looking? Here is the script: <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = ""; $name = $email = $gender = $comment = $website = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) {$nameErr = "Name is required";} else {$name = test_input($_POST["name"]);} if (empty($_POST["email"])) {$emailErr = "Email is required";} else {$email = test_input($_POST["email"]);} if (empty($_POST["website"])) {$website = "";} else {$website = test_input($_POST["website"]);} if (empty($_POST["comment"])) {$comment = "";} else {$comment = test_input($_POST["comment"]);} if (empty($_POST["gender"])) {$genderErr = "Gender is required";} else {$gender = test_input($_POST["gender"]);} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP Form Validation Example</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Website: <input type="text" name="website"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"></textarea> <br><br> Gender: <input type="radio" name="gender" value="female">Female <input type="radio" name="gender" value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> <?php echo "<h2>Your Input:</h2>"; echo $name; echo "<br>"; echo $email; echo "<br>"; echo $website; echo "<br>"; echo $comment;
-
Undefined Index notice
@NOCK. You are the man, that worked. Thanks very much. I wish I had your knowledge.