944,121 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2966
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 12th, 2007
0

Simple PHP Question

Expand Post »
Ok here is my code:

PHP Syntax (Toggle Plain Text)
  1.  
  2. <html>
  3.  
  4. <head>
  5. <title> PHP Test Page </title>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <?php
  11.  
  12. echo date("H:i");
  13. echo gmdate("M d Y");
  14.  
  15. $counter_file = "count.dat";
  16.  
  17. if(!($fp = fopen($counter_file, "r"))) die ("Cannot open $counter_file.");
  18. $counter = (int) fread($fp, 20);
  19. fclose($fp);
  20.  
  21. $counter++;
  22.  
  23. echo "You're visitor No. $counter.";
  24. $fp = fopen($counter_file, "w");
  25. fwrite($fp, $counter);
  26. fclose($fp);
  27.  
  28. ?>
  29. </body>
  30.  
  31. </html>

this makes output saying:

PHP Syntax (Toggle Plain Text)
  1.  
  2. 18:32Mar 12 2007You're visitor No. 5.
  3.  

how can i make it so that they are on different lines, e.g

PHP Syntax (Toggle Plain Text)
  1.  
  2. 18:32
  3. Mar 12 2007
  4. You're visitor No. 5.
  5.  
Last edited by jbennet; Mar 12th, 2007 at 3:41 pm.
Similar Threads
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005
Mar 12th, 2007
0

Re: Simple PHP Question

<br>

Possibly?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 12th, 2007
0

Re: Simple PHP Question

ah yes

now heres a harder question, my site now looks like this

PHP Syntax (Toggle Plain Text)
  1.  
  2. <html>
  3.  
  4. <head>
  5.  
  6. <title> PHP Test Page </title>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <h3><b><u>James Computers Order Form</u></b></h3>
  12.  
  13. <form action="process.php" method="post">
  14.  
  15. <select name="item">
  16. <option>Computers</option>
  17. <option>Monitors</option>
  18. <option>PDA's</option>
  19. </select>
  20.  
  21. Quantity: <input name="quantity" type="text" />
  22. <input type="submit" />
  23.  
  24. </form>
  25.  
  26. <?php
  27.  
  28. echo date("H:i");
  29. echo ", ";
  30. echo gmdate("M d Y");
  31.  
  32. $counter_file = "count.dat";
  33. if(!($fp = fopen($counter_file, "r"))) die ("<p><h4>Cannot open $counter_file.</h4></p>");
  34. $counter = (int) fread($fp, 20);
  35. fclose($fp);
  36.  
  37. $counter++;
  38.  
  39. echo "<p><h4>You are visitor number $counter</h4></p>";
  40.  
  41. $fp = fopen($counter_file, "w");
  42. fwrite($fp, $counter);
  43. fclose($fp);
  44.  
  45. ?>
  46.  
  47. </body>
  48. </html>
  49.  

process.php looks like this:

PHP Syntax (Toggle Plain Text)
  1.  
  2. <html>
  3. <body>
  4.  
  5. <?php
  6. $quantity = $_POST['quantity'];
  7. $item = $_POST['item'];
  8. echo "You ordered ". $quantity . " " . $item . ".<br />";
  9. echo "Thank you for ordering from James Computers!";
  10. ?>
  11.  
  12. </body>
  13. </html>


can anyone point me in the right direction of how to get this form to link with a mysql database
Last edited by jbennet; Mar 12th, 2007 at 4:38 pm.
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005
Mar 12th, 2007
0

Re: Simple PHP Question

As long as you supply the correct path to your database and the correct password.

Then select the correct database you should be good to go.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 12th, 2007
0

Re: Simple PHP Question

ok i did it i used this site (veery good)

http://www.freewebmasterhelp.com/tutorials/phpmysql
Last edited by jbennet; Mar 12th, 2007 at 5:52 pm.
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005
Mar 12th, 2007
0

Re: Simple PHP Question

ok one final problem:

PHP Syntax (Toggle Plain Text)
  1.  
  2. <html>
  3.  
  4. <head>
  5. <title>Test MYSQL PHP Page</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <h3><b><u>Test MYSQL PHP Page</u></b></h3>
  11.  
  12. <form action="insert_script.php" method="post">
  13.  
  14. <TABLE BORDER="1">
  15. <tr>
  16. <td>First Name: </td>
  17. <td><input type="text" name="first"><br></td>
  18. </tr>
  19. <tr>
  20. <td>Last Name:</td>
  21. <td><input type="text" name="last"><br></td>
  22. </tr>
  23. <tr>
  24. <td>Phone:</td>
  25. <td><input type="text" name="phone"><br></td>
  26. </tr>
  27. <tr>
  28. <td>Mobile:</td>
  29. <td><input type="text" name="mobile"><br></td>
  30. </tr>
  31. <tr>
  32. <td>E-mail: </td>
  33. <td><input type="text" name="email"><br></td>
  34. </tr>
  35.  
  36. <input type="Submit">
  37. </form>
  38. <?php
  39.  
  40. echo date("H:i");
  41. echo ", ";
  42. echo gmdate("M d Y");
  43.  
  44. $counter_file = "count.dat";
  45. if(!($fp = fopen($counter_file, "r"))) die ("<p><h4>Cannot open $counter_file.</h4></p>");
  46. $counter = (int) fread($fp, 20);
  47. fclose($fp);
  48.  
  49. $counter++;
  50.  
  51. echo "<p><h4>You are visitor number $counter</h4></p>";
  52.  
  53. $fp = fopen($counter_file, "w");
  54. fwrite($fp, $counter);
  55. fclose($fp);
  56.  
  57. ?>
  58.  
  59. <hr>
  60. <h3><b><u>Database Tools</u></b></h3>
  61. <a href="tbl_create_script.php">(Re)install database table</a>
  62. <p>
  63. <a href="output_page.php">See output</a>
  64. <p>
  65. <hr>
  66.  
  67. </body>
  68. </html>

this is wierd. it puts the form on the bottom, button at the top and links in the middle?

i want the form, then the button then the links

screenshot enclosed

can anyone help me
Attached Thumbnails
Click image for larger version

Name:	php.JPG
Views:	16
Size:	21.8 KB
ID:	3011  
Last edited by jbennet; Mar 12th, 2007 at 6:45 pm.
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005
Mar 13th, 2007
0

Re: Simple PHP Question

hii
give <br> after the time , date and count
i.e echo "<br>";

that should work
Reputation Points: 10
Solved Threads: 0
Light Poster
php_coder is offline Offline
34 posts
since Dec 2006
Mar 13th, 2007
0

Re: Simple PHP Question

i ended up fixing it thanks
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005
Mar 18th, 2007
0

Re: Simple PHP Question

Click to Expand / Collapse  Quote originally posted by jbennet ...
Ok here is my code:

PHP Syntax (Toggle Plain Text)
  1.  
  2. <html>
  3.  
  4. <head>
  5. <title> PHP Test Page </title>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <?php
  11.  
  12. echo date("H:i");
  13. echo gmdate("M d Y");
  14.  
  15. $counter_file = "count.dat";
  16.  
  17. if(!($fp = fopen($counter_file, "r"))) die ("Cannot open $counter_file.");
  18. $counter = (int) fread($fp, 20);
  19. fclose($fp);
  20.  
  21. $counter++;
  22.  
  23. echo "You're visitor No. $counter.";
  24. $fp = fopen($counter_file, "w");
  25. fwrite($fp, $counter);
  26. fclose($fp);
  27.  
  28. ?>
  29. </body>
  30.  
  31. </html>

this makes output saying:

PHP Syntax (Toggle Plain Text)
  1.  
  2. 18:32Mar 12 2007You're visitor No. 5.
  3.  

how can i make it so that they are on different lines, e.g

PHP Syntax (Toggle Plain Text)
  1.  
  2. 18:32
  3. Mar 12 2007
  4. You're visitor No. 5.
  5.  


Just use a <br> tags within an echo. like this


echo' <br>';

after each output that you want to see
Reputation Points: 11
Solved Threads: 1
Junior Poster
anastacia is offline Offline
142 posts
since Nov 2004
Mar 18th, 2007
0

Re: Simple PHP Question

thanks man
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: What will a flash xml socket connect to - please help - insanity is near
Next Thread in PHP Forum Timeline: session question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC