Jump to content

morocco-iceberg

Members
  • Posts

    100
  • Joined

Everything posted by morocco-iceberg

  1. I was using the print_r to show the entire array. This is what I get when I print it out... I think the problem happens when I'm tryinto put it into an array, but I can't find any solutions. Array ( [0] => Array ( [Question 1.] => [Question 2.] => [Question 3.] => [Question 4.] => [Question 5.] => ) )
  2. I'm trying to get an array that I've populated using a database to shuffle so that I can use it to ouput a random question. Here's my code: <?php mysql_connect("server", "user", "password") or die(mysql_error()); echo "Connected to MySQL<br/>"; mysql_select_db("database") or die(mysql_error()); echo "Connected to Database"; $result = mysql_query('SELECT * FROM table') or exit(mysql_error()); while ($row = mysql_fetch_assoc($result)){ $array[] = $row; } shuffle($array); print_r($array); ?> This doesn't seem to shuffle it at all... Any help is greatly appreciated.
  3. I guess I should have said so. I'm supposed to have the three seperate arrays according to the amount of days in each month.
  4. I actually have to do it using arrays, its a homework assignment, lol, no way I would have used arrays for this purpose unless I was made to.
  5. Just wondering if there's a better/neater way to do this? <?php $a=array("February"); $b=array("April","June","September","November"); $c=array("January","March","May","July","August","October","December"); echo $c[0]; to(); echo "<br/>"; echo $a[0]; te(); echo "<br/>"; echo $c[1]; to(); echo "<br/>"; echo $b[0]; t(); echo "<br/>"; echo $c[2]; to(); echo "<br/>"; echo $b[1]; t(); echo "<br/>"; echo $c[3]; to(); echo "<br/>"; echo $c[4]; to(); echo "<br/>"; echo $b[2]; t(); echo "<br/>"; echo $c[5]; to(); echo "<br/>"; echo $b[3]; t(); echo "<br/>"; echo $c[6]; to(); echo "<br/>"; function te(){ $counter=0; while($counter<28){ $counter=$counter+1; echo " $counter "; } } function t(){ $counter=0; while($counter<30){ $counter=$counter+1; echo " $counter "; } } function to(){ $counter=0; while($counter<31){ $counter=$counter+1; echo " $counter "; } } ?>
  6. I'm supposed to use a do while loop to list the names of the children... and everything I've attempted just won't work. There are three pages: Page One asks how many children the person has... <form action="kids.php" method="post"> How many children do you have? <input type="text" name="number" value="" /> <input type="submit" name="one" value="Next" /> Page Two then asks for the childrens names and genereates an input box per child... <?php $number=$_POST['number']; echo "You have $number children.<br /><form action=\"kidsResults.php\" method=\"post\"><input type=\"hidden\" name=\"number\" value=\"$number\" />"; for($counter=1;$counter<=$number;$counter+=1){ echo "Name of child $counter <input type=\"text\" name=\"$counter\" value=\"\" />"; } echo "<input type=\"submit\" name=\"two\" value=\"Next\" /></form>" ?> But I can't seem to get my head around Page Three, which is supposed to list the children's names... <?php $number=$_POST['number']; $counter=0; while($counter<=$number){ $counter=$counter+1; $counter=$_POST['$counter']; echo $counter; } ?> Help!
  7. The code links to test2.php because I copied the multi-line code from that file. The code will be required to work on whiever new page is created, so I've used the variable $label.php in the action part of the form.
  8. >.<;; I suck at explaining things. Here's the basics: I have a file named write.php. This file contains code that allows one to publish an article to a new file, created when they sumbit the form. This code also creates a link in a file called link.txt I then have a file called read.php. This file opens link.txt, reads its list of links and then echos them onto the screen. Each of these links leads to a seperate page with a seperate article. I have created a working code that allows visitors to these articles to comment, however I have not been able to implement it on the seperate pages. What I want to do, is when I create a new page for a new article, is to include the comment php so that when I go to the page with the article on it, ican post and read comments. My attempt to do this through the variable $blog came up with the expecting a 'T_string' parse error. Is there anyway that I can insert the php into each new page as they are created?
  9. Thanks for trying to help, but thats not what I want. I know HTML and I know basic php, and I already had a working comment code, I was simply trying to write it to each file that I create with another php code, basically a blog system and each article can be commented on. I have working codes, just not when I try to put one inside the other.
  10. Here's the commenting code on multiple lines, do i simply need to make sure all quotes are slashed out or must I do more to it? <?php /* shows previously published comments */ $commentFile=\"blog/$label.txt\"; $readComment=fopen($commentFile,\'r\'); $showComment=fread($readComment,filesize($commentFile)); fclose($readComment); echo $showComment; /* creates new comment from form */ if(isset($_POST[\'submit\'])){ $addComment=fopen($commentFile,\'a\'); $comment=$_POST[\'comment\']; $author=$_POST[\'author\']; $time=date(\"g:i a M j, Y\"); $commentDetails=\"<br/><br/><p>$comment</p><h4>$author @ $time</h4><br/>\"; fwrite($addComment,$commentDetails); fclose($addComment); echo \"Your comment has been added. Please refresh this page to see it.<br/><br/>\"; } ?> <!-- comment form --> <form action=\"test2.php\" method=\"post\"> <strong>Comment:</strong><br/> <input type=\"text\" name=\"comment\" value=\"\"/><br/> <strong>Author:</strong><br/> <input type=\"text\" name=\"author\" value=\"\"/><br/><br/> <input type=\"submit\" name=\"submit\" value=\"Submit\"/> </form>
  11. No, because I'm sure the forum uses databases but I don't know how to and only want a simple code for my assignment as we haven't been taught how to use databases yet, simply how to write to files etc. I put it all on one line because in notepad++ when I put it on multiple lines it regained its colour instead of staying grey. If I can put it on multiple lines and still write it to a file then I'll do that.
  12. Thats a php script that I want written to the new file to allow visitors to comment on it.
  13. Here's the line causing the error. This line is the data that is supposed to written to a new page. blog="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Subscribe to Club Newsletter</title></head><body><h2>.$title.</h2><p>.$article.</p><h4>.$author. @ .$time.</h4><br/><br/><?php $commentFile=\".$label..txt\"\; $readComment=fopen(.$commentFile.,\'r\')\; .$showComment.=fread(.$readComment.,filesize(.$commentFile.))\; fclose($readComment)\; echo .$showComment.\; if(isset($_POST[\'commentsubmit\'])){ .$addComment.=fopen(.$commentFile.,\'a\')\; .$comment.=$_POST[\'comment\']\; .$commentauthor.=$_POST[\'commentauthor\']\; .$commenttime.=date(\"g:i a M j, Y\")\; .$commentDetails.=\"<br/><br/><p>.$comment.</p><h4>.$commentauthor. @ .$commenttime.</h4><br/>\"\; fwrite(.$addComment.,.$commentDetails.)\; fclose(.$addComment.)\; echo \"Your comment has been added. Please refresh this page to see it.<br/><br/>\"; } ?> <!-- comment form --><form action=\".$label..php\" method=\"post\"><strong>Comment:</strong><br/><input type=\"text\" name=\"comment\" value=\"\"/><br/><strong>Author:</strong><br/><input type=\"text\" name=\"commentauthor\" value=\"\"/><br/><br/><input type=\"submit\" name=\"commentsubmit\" value=\"Submit\"/></form></body></html>";
  14. Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\write.php on line 25 I don't understand what this means...
  15. So far? Nothing other than playing with creating them and tables and adding information within the mysql monitor.
  16. Sounds like a better way than anything I can think of. No idea how to do that though...
  17. I'm attempting to code a blog system, and have currently go the ability to write a blog that is displayed on a seperate page, that can then be commented upon by visitors. What I would like to achieve now is a system that archives the blogs into seperate pages, whilst creating a link on the main page to each of these pages automatically. Any ideas of how to go about this?
  18. Haha, oh dear I am blonde... my code was fine, I was just linking to the wrong page via my form.
  19. Ok, so I was going smoothly until all of a sudden I started getting parse errors on line 21. I have no clue what is wrong with my code, so any help is very muchly appreciated! <!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=UTF-8" /> <title>File Writing</title> </head> <body> <?php if(isset($_POST['submit'])){ $name=$_POST['name']; $email=$_POST['email']; $message=$_POST['message']; $to="info@klds.com.au"; $re=$_POST['subject']; $msg = "$message \r\n \r\n $name, \r\n $email"; if(!$name){ $errn="Please enter your name."; }else if(!$email){ $erre="Please enter an email."; }else if(!$re){ $errr="Please enter a subject."; }else if(!$message){ $errm="Please enter a message."; }else{ $email = trim($email); $_ename = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}~]+"; $_host = "([0-9A-Z]+\.)+"; $_tlds = "([0-9A-Z]){2,4}$/i"; if ( !preg_match($_ename."@".$_host.$_tlds,$email)){ echo "Sorry, it appears the e-mail address you have entered is not valid. Please enter a valid e-mail address."; }else{ mail($to, $re, $msg); echo "Message sent."; } } } ?> <form action="file.php" method="post"> <strong>Name</strong> <input type="input" name="name" value="<?php if(isset($_POST['submit'])){echo $name;} ?>" /><?php if(isset($_POST['submit'])){echo $errn;} ?><br/> <strong>E-Mail</strong> <input type="input" name="email" value="<?php if(isset($_POST['submit'])){echo $email;} ?>" /><br/><?php if(isset($_POST['submit'])){echo $erre;} ?> <strong>Subject</strong> <input type="input" name="subject" value="<?php if(isset($_POST['submit'])){echo $re;} ?>" /><br/><?php if(isset($_POST['submit'])){echo $errr;} ?> <strong>Message</strong> <input type="input" name="message" value="<?php if(isset($_POST['submit'])){echo $message;} ?>" /><br/><br/><?php if(isset($_POST['submit'])){echo $errm;} ?> <input type="submit" name="submit" value="Submit" /> </form> </body> </html>
  20. Thanks! it was the spaces in the form fields that were doing it. And thanks for the links.
  21. I'm having difficulties getting my form to work properly, it seems to ignore the first 'if' section even if the fields have nothing in them and skips to the email validation. Help? Alos it would be cool if someone could help me with making it spam proof? Thanks.. <?php $subject = $_POST['subject']; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $what = $_POST['what']; $re = $subject; $to = "info@klds.com.au"; $msg = "$message \r\n \r\n $name, \r\n $email"; if (!$subject||!$name||!$email||!$message||!$what){ echo "Error: All fields must be completed!"; }else if($what!="Green"||$what!="green"){ echo "You got the question wrong! Please try again."; }else{ $email = trim($email); $_ename = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}~]+"; $_host = "([0-9A-Z]+\.)+"; $_tlds = "([0-9A-Z]){2,4}$/i"; if (!preg_match($_ename."@".$_host.$_tlds,$email)){ echo "E-mail address is not valid. Please enter a valid e-mail address."; }else{ mail($to, $re, $msg); echo "Thank-you for your enquiry, your message was succesfully sent. We'll get back to you as soon as possible."; } } ?>
×
×
  • 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.