PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
OuchMedia
Forum Newbie
Posts: 11 Joined: Mon Nov 24, 2003 10:48 pm
Post
by OuchMedia » Tue Nov 25, 2003 5:54 pm
i have a script that is taking information from a form writing it to a file...the script is as follows:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
Code: Select all
<?php
//Define your variables here
$date = $_POST['name'];
$name = $_POST['title'];
$company = $_POST['company'];
$address = $_POST['address'];
$location = $_POST['location'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$description = $_POST['description'];
//The above define your variables sent from your "form.php" file
$fp = fopen("quotes.txt", "a");
$outputstring = "$date.\n\r\r.
Name $name.\n\n\r
Title $title.\n\n\r
Company $company.\n\n\r
Address $address.\n\n\r
City, State $location.\n\n\r
Zipcode $zipcode.\n\n\r
Phone $phone.\n\n\r
Email $email.\n\n\r
Text $description.\n\n\r";
fwrite($fp, $outputstring);
fclose($fp);
?>
<h1>ouch media</h1>
<h2>form results</h2>
</body>
</html>
the text that the script is writing in the file isn't complete. for one thing, the date isn't shown...also, the only text from the form that shows is from $title; none of the others have any text displayed from the form.
.
.
Name .
Title president.
Company .
Address .
City, State .
Zipcode .
Phone .
Email .
Text .
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Tue Nov 25, 2003 6:02 pm
Please post the code for the form as well please.
OuchMedia
Forum Newbie
Posts: 11 Joined: Mon Nov 24, 2003 10:48 pm
Post
by OuchMedia » Tue Nov 25, 2003 6:11 pm
here is the code for the form:
sorry, it is very long
Code: Select all
<form action="submit.php" name="Contact Form" method="post">
<table border="0" cellpadding="0" cellspacing="0" width="443">
<tr>
<td width="125" valign="middle" bgcolor="#0BB1FE">
<h4>Name</h4>
</td>
<td width="288" valign="middle" bgcolor="#0BB1FE"><input type="text" name="name" size="40" tabindex="1"></td>
</tr>
<tr>
<td width="125" valign="middle" bgcolor="#dddddd">
<h4>Title</h4>
</td>
<td width="288" valign="middle" bgcolor="#dddddd"><input type="text" name="title" size="40" tabindex="2"></td>
</tr>
<tr>
<td width="125" valign="middle" bgcolor="#0BB1FE">
<h4>Company</h4>
</td>
<td width="288" valign="middle" bgcolor="#0BB1FE"><input type="text" name="company" size="40" tabindex="3"></td>
</tr>
<tr>
<td width="125" bgcolor="#dddddd">
<h4>Address</h4>
</td>
<td width="288" bgcolor="#dddddd" valign="middle"><input type="text" name="address" size="40" tabindex="4"></td>
</tr>
<tr>
<td width="125" bgcolor="0BB1FE">
<h4>City, State</h4>
</td>
<td width="288" bgcolor="0BB1FE" valign="middle"><input type="text" name="location" size="40" tabindex="5"></td>
</tr>
<tr>
<td width="125" bgcolor="#dddddd">
<h4>Zipcode</h4>
</td>
<td width="288" bgcolor="#dddddd" valign="middle"><input type="text" name="zipcode" size="40" tabindex="6"></td>
</tr>
<tr>
<td width="125" bgcolor="0BB1FE">
<h4>Phone</h4>
</td>
<td width="288" bgcolor="0BB1FE" valign="middle"><input type="text" name="phone" size="40" tabindex="7"></td>
</tr>
<tr>
<td width="125" bgcolor="#dddddd">
<h4>Email</h4>
</td>
<td width="288" bgcolor="#dddddd" valign="middle"><input type="text" name="email" size="40" tabindex="8"></td>
</tr>
<tr>
<td width="125" bgcolor="0BB1FE">
<h4>Project Description<br>
or Question</h4>
</td>
<td width="288" bgcolor="0BB1FE" valign="middle"><textarea name="description" cols="30" rows="4" tabindex="9"></textarea></td>
</tr>
<tr>
<td width="125" bgcolor="dddddd"><font color="#99cccc"><br>
</font></td>
<td width="288" bgcolor="dddddd">
<div align="left">
<input type="submit" name="submitContact" value="Submit" tabindex="10"></div>
<p><font color="0BB1FE">.</font></p>
</td>
</tr>
</table>
</form>
lc
Forum Contributor
Posts: 188 Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands
Post
by lc » Tue Nov 25, 2003 8:39 pm
Form looks fine but I'd make your piece of code into:
Code: Select all
<?php
$fp = fopen("quotes.txt", "a");
$outputstring = "$date.\r\n.Name $name.\r\nTitle $title.\r\nCompany $company.\r\nAddress $address.\r\nCity, State $location.\r\nZipcode $zipcode.\r\nPhone $phone.\r\nEmail $email.\r\nText $description.\r\n";
fwrite($fp, $outputstring);
fclose($fp);
?>
so \r\n in stead of \n\n\r and all data on a single line. (maybe just my habit)
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Nov 26, 2003 2:30 am
Please don't keep splitting the topic each time you have a different question. If you feel it very neccessary you should at the least post to the other threads stating that the problem in them was solved, otherwise you will have three threads on the same code and a big mess of confusion.
Mac
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Nov 26, 2003 2:31 am
If you put:
Code: Select all
echo '<pre>$_POST - ';
print_r($_POST);
echo '</pre>';
echo '<pre>$HTTP_POST_VARS - ';
print_r($HTTP_POST_VARS);
echo '</pre>';
at the top of your form processing script do you get anything?
Mac
OuchMedia
Forum Newbie
Posts: 11 Joined: Mon Nov 24, 2003 10:48 pm
Post
by OuchMedia » Wed Nov 26, 2003 9:15 am
adding
Code: Select all
echo '<pre>$_POST - ';
print_r($_POST);
echo '</pre>';
echo '<pre>$HTTP_POST_VARS - ';
print_r($HTTP_POST_VARS);
echo '</pre>';
didn't fix the problem...it only caused this:
$_POST -
$HTTP_POST_VARS - Array
(
[name] => test
[title] => test
[company] => test
[address] => test
[location] => test
[zipcode] => test
[phone] => test
[email] => test
[description] => test
[submitContact] => Submit
)
to appear on the screen above the text that normally appears. the only thing that was written to the flat file was text in the "title" field. any other ideas?
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Nov 26, 2003 9:57 am
It wasn't intended to fix the problem - it was a tool to diagnose the problem, print_r() allows you to quickly check the content of an array.
From the output you posted it is evident that there is nothing in the $_POST array, but there is information in the $HTTP_POST_VARS array. Based on this I would assume that you are using a version of PHP older than 4.1. You should change all instances of $_POST in your code to $HTTP_POST_VARS.
Mac
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Nov 26, 2003 10:11 am
try this
Code: Select all
<?php
//Define your variables here
$date = $_POST['name'];
$name = $_POST['title'];
$company = $_POST['company'];
$address = $_POST['address'];
$location = $_POST['location'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$description = $_POST['description'];
//The above define your variables sent from your "form.php" file
$fp = fopen("quotes.txt", "a");
$outputstring = $date.\n\r\r.
"Name" .$name.\n\n\r
"Title" .$title.\n\n\r
"Company" .$company.\n\n\r
"Address" .$address.\n\n\r
"City, State" .$location.\n\n\r
"Zipcode" .$zipcode.\n\n\r
"Phone" .$phone.\n\n\r
"Email" .$email.\n\n\r
"Text" .$description.\n\n\r;
fwrite($fp, $outputstring);
fclose($fp);
?>
i'm assuming what you had infront of the $vars in the $outputstring var is what you wanted to be put in front of the $vars pulled from the form, if so you have to define them as strings and $vars can't be put in "quotes".
OuchMedia
Forum Newbie
Posts: 11 Joined: Mon Nov 24, 2003 10:48 pm
Post
by OuchMedia » Wed Nov 26, 2003 12:46 pm
changing the _POST to HTTP_POST_VARS fixed the whole problem; thanks a bunch!!!