954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Simple PHP Question

Ok here is my code:

<html>
 
<head>
<title> PHP Test Page </title>
</head>
 
<body>
 
<?php
 
echo date("H:i");
echo gmdate("M d Y");
 
$counter_file = "count.dat";
 
if(!($fp = fopen($counter_file, "r"))) die ("Cannot open $counter_file.");
$counter = (int) fread($fp, 20);
fclose($fp);
 
$counter++;
 
echo "You're visitor No. $counter.";
$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
 
?>
</body>
 
</html>


this makes output saying:

18:32Mar 12 2007You're visitor No. 5.


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

18:32
Mar 12 2007
You're visitor No. 5.
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 


Possibly?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

ah yes :)

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

<html>
 
<head>
 
<title> PHP Test Page </title>
</head>
 
<body>
 
<h3><b><u>James Computers Order Form</u></b></h3>
 
<form action="process.php" method="post"> 
 
<select name="item"> 
<option>Computers</option>
<option>Monitors</option>
<option>PDA's</option>
</select>
 
Quantity: <input name="quantity" type="text" /> 
<input type="submit" />
 
</form>
 
<?php
 
echo date("H:i");
echo ", ";
echo gmdate("M d Y");
 
$counter_file = "count.dat";
if(!($fp = fopen($counter_file, "r"))) die ("<p><h4>Cannot open $counter_file.</h4></p>");
$counter = (int) fread($fp, 20);
fclose($fp);
 
$counter++;
 
echo "<p><h4>You are visitor number $counter</h4></p>";
 
$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
 
?>
 
</body>
</html>


process.php looks like this:

<html>
<body>
 
<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];
echo "You ordered ". $quantity . " " . $item . ".";
echo "Thank you for ordering from James Computers!";
?>
 
</body>
</html>



can anyone point me in the right direction of how to get this form to link with a mysql database

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

http://www.freewebmasterhelp.com/tutorials/phpmysql

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

ok one final problem:

<html>
 
<head>
<title>Test MYSQL PHP Page</title>
</head>
 
<body>
 
<h3><b><u>Test MYSQL PHP Page</u></b></h3>
 
<form action="insert_script.php" method="post">
 
<TABLE BORDER="1">
<tr>
<td>First Name: </td>
<td><input type="text" name="first"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="last"></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<td>Mobile:</td>
<td><input type="text" name="mobile"></td>
</tr>
<tr>
<td>E-mail: </td>
<td><input type="text" name="email"></td>
</tr>
 
<input type="Submit">
</form>
<?php
 
echo date("H:i");
echo ", ";
echo gmdate("M d Y");
 
$counter_file = "count.dat";
if(!($fp = fopen($counter_file, "r"))) die ("<p><h4>Cannot open $counter_file.</h4></p>");
$counter = (int) fread($fp, 20);
fclose($fp);
 
$counter++;
 
echo "<p><h4>You are visitor number $counter</h4></p>";
 
$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
 
?>
 
<hr>
<h3><b><u>Database Tools</u></b></h3>
<a href="tbl_create_script.php">(Re)install database table</a> 
<p>
<a href="output_page.php">See output</a> 
<p>
<hr>
 
</body>
</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

Attachments php.JPG 21.78KB
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

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

that should work :)

php_coder
Light Poster
34 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

i ended up fixing it thanks

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

Ok here is my code:

<html>
 
<head>
<title> PHP Test Page </title>
</head>
 
<body>
 
<?php
 
echo date("H:i");
echo gmdate("M d Y");
 
$counter_file = "count.dat";
 
if(!($fp = fopen($counter_file, "r"))) die ("Cannot open $counter_file.");
$counter = (int) fread($fp, 20);
fclose($fp);
 
$counter++;
 
echo "You're visitor No. $counter.";
$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
 
?>
</body>
 
</html>

this makes output saying:

18:32Mar 12 2007You're visitor No. 5.

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

18:32
Mar 12 2007
You're visitor No. 5.

Just use a
tags within an echo. like this


echo'
';

after each output that you want to see

anastacia
Junior Poster
142 posts since Nov 2004
Reputation Points: 11
Solved Threads: 1
 

thanks man

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

its simple you didnt cole yopur tag.


your php code put it our=tside the tavble tag

anastacia
Junior Poster
142 posts since Nov 2004
Reputation Points: 11
Solved Threads: 1
 

To both put a space character between your time and date, and to break the line between the Date/Time and the Visitor count change the lines:

echo date("H:i");
echo gmdate("M d Y");

to

echo date("H:i") . " ";
echo gmdate("M d Y") . "
";

That will put a space between the time and the date,
and will put a HTML line break before the Visitor message.

JEofVB
Newbie Poster
1 post since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You