Simple PHP Question

Reply

Join Date: Apr 2005
Posts: 16,153
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Simple PHP Question

 
0
  #1
Mar 12th, 2007
Ok here is my code:

  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:

  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

  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.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Simple PHP Question

 
0
  #2
Mar 12th, 2007
<br>

Possibly?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,153
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Simple PHP Question

 
0
  #3
Mar 12th, 2007
ah yes

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

  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:

  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.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Simple PHP Question

 
0
  #4
Mar 12th, 2007
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,153
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Simple PHP Question

 
0
  #5
Mar 12th, 2007
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.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,153
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Simple PHP Question

 
0
  #6
Mar 12th, 2007
ok one final problem:

  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
Last edited by jbennet; Mar 12th, 2007 at 6:45 pm.
Attached Thumbnails
php.JPG  
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 34
Reputation: php_coder is an unknown quantity at this point 
Solved Threads: 0
php_coder php_coder is offline Offline
Light Poster

Re: Simple PHP Question

 
0
  #7
Mar 13th, 2007
hii
give <br> after the time , date and count
i.e echo "<br>";

that should work
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,153
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Simple PHP Question

 
0
  #8
Mar 13th, 2007
i ended up fixing it thanks
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 140
Reputation: anastacia is an unknown quantity at this point 
Solved Threads: 1
anastacia's Avatar
anastacia anastacia is offline Offline
Junior Poster

Re: Simple PHP Question

 
0
  #9
Mar 18th, 2007
Originally Posted by jbennet View Post
Ok here is my code:

  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:

  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

  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
:lol: I am not one of those who wait for things to happen, :p but one of those who make things happen ;)
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,153
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Simple PHP Question

 
0
  #10
Mar 18th, 2007
thanks man
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC