LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP and HTML Form Post (https://www.linuxquestions.org/questions/programming-9/php-and-html-form-post-199565/)

Savahn 06-30-2004 01:40 PM

PHP and HTML Form Post
 
I am trying to get the FORM POST METHOD to work with a PHP script I have written. The script enters the data from the forms into a text file and emails the same data to a specific email address. When I access the webpage and enter my data then go and check the text file the only inside is the date... the same with the email that is sent. The linux server I running this script one is Slackware 10.0 with Apache 2 and the latest version of PHP. It acts as thou the form is not posting anything to the script but I know it is running the script. Please help!!!

david_ross 06-30-2004 01:51 PM

Perhaps it has been coded worng or it has been written to require that you have "register globals" set to "on" in your php configuration file.

Savahn 06-30-2004 01:58 PM

I have tried several different PHP scripts to include formmail. Global_registers is set to on and I have tried to set it to off as well. Same problem.

david_ross 06-30-2004 02:01 PM

Can you post a copy of what isn't working?

Savahn 06-30-2004 02:03 PM

Here is the PHP script. It worked before I rebuilt the current system and install Slackware 10 instead of Redhat 7.3.

<html>


<head>


<title></title>


</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">


<?






$space = "_______________";


$contact_db = fopen("contact.txt", "a");



$linevar = ereg_replace("<br>","n",$linevar);


$date = date("l, F dS, Y - h:i:s A");


fwrite($contact_db, $date."\r\n");


fwrite($contact_db, $space."\r\n\r\n");


// Edit the following coding


// replace textfield1 with the name of the first textfield on your email form
// Continue this process for textfield 2 through to 15


fwrite($contact_db, $firstname."\r\n");


fwrite($contact_db, $address."\r\n");


fwrite($contact_db, $city."\r\n");


fwrite($contact_db, $zipcode."\r\n");


fwrite($contact_db, $phone."\r\n");


fwrite($contact_db, $dialup."\r\n");


fwrite($contact_db, $cardtype."\r\n");


fwrite($contact_db, $cc."\r\n");


fwrite($contact_db, $exp1."\r\n");


fwrite($contact_db, $exp2."\r\n");


fwrite($contact_db, $total."\r\n");


fwrite($contact_db, $notes."\r\n\r\n");


fclose($contact_db);


// replace youremail@domain.com with the email you woudl like your form to submit to
// replace the Header titles with the headers you would like displayed in your email application
// replace the textfield variables wtih the names of the corresponding text fields on your form


mail("ADDEMAILADDRESS HERE", "Online Credit Card Payment", "Name on Card: $name\r\n\r\n Billing Address: $address\r\n\r\n City: $city\r\n\r\n Zip: $zipcode\r\n\r\n Home Number: $phone\r\n\r\n Dialup Account Number: $dialup\r\n\r\n Payment Type: $cardtype\r\n\r\n Credit Card #: $cc\r\n\r\n CC Expiration: $exp1, $exp2\r\n\r\n Amount to Charge Card: $total\r\n\r\n Notes and/or Addl Emails: $notes\r\n\r\n");


?>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<table width="250" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="10"><img src="../../contact_form_submit/place_holder.gif" width="5" height="180"></td>
<td width="240" valign="top">
<div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
<b><font color="#003366"><br>
<br>
<font size="2">Thank you!</font><br>
<br>
</font></b><font color="#003366">Your e-mail has been sent,
<br>
and the account will be credited in 1 - 2 business days.<br>
<br>
</font><font color=#ffffff face="Verdana, Arial, Helvetica, sans-serif"
size=2><b> </b></font></font>


<font size="1" face="Verdana, Arial, Helvetica, sans-serif"><font color="#003366"><br>
<br>

</font></font></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>


</td>
</tr>
</table>
</body>


</html>

Savahn 06-30-2004 02:04 PM

Here is the webpage.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="center">
<form name="form1" method="post" action="submit.php">
<table width="75%" border="1">
<tr>
<td colspan="2"><div align="center"><strong></strong></div></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="50%"><div align="right">Name (As it appears on card)<strong>
:</strong></div></td>
<td width="50%"><input type="text" name="firstname"></td>
</tr>
<tr>
<td><div align="right">Billing Address<strong> :</strong></div></td>
<td><input type="text" name="address"></td>
</tr>
<tr>
<td><div align="right">City <strong>:</strong></div></td>
<td><input type="text" name="city"></td>
</tr>
<tr>
<td><div align="right">Zip Code<strong> :</strong></div></td>
<td><input type="text" name="zipcode"></td>
</tr>
<tr>
<td><div align="right">Home Number<strong> :</strong></div></td>
<td><input name="phone" type="text" value="931-"></td>
</tr>
<tr>
<td><div align="right">Dial Up Access Number<strong> :</strong></div></td>
<td><select name="dialup" size="1">
<option value="563-4027">Coffee County 563-4027</option>
<option value="536-4027">Bedford County 536-4027</option>
<option value="386-4007">Franklin County 386-4007</option>
</select></td>
</tr>
<tr>
<td><div align="right">Payment Type<strong> :</strong></div></td>
<td><select name="cardtype" size="1">
<option value="Visa" selected>Visa</option>
<option value="Mastercard">Mastercard</option>
</select></td>
</tr>
<tr>
<td><div align="right">Credit Card Number<strong> :</strong></div></td>
<td><input type="text" name="cc"></td>
</tr>
<tr>
<td height="47">
<div align="right">Expiration Date<strong> :</strong></div></td>
<td><select name="exp1">
<option value="01" selected>01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name="exp2" size="1">
<option value="04" selected>2004</option>
<option value="05">2005</option>
<option value="06">2006</option>
<option value="07">2007</option>
<option value="08">2008</option>
<option value="09">2009</option>
<option value="10">2010</option>
</select></td>
</tr>
<tr>
<td><div align="right">Amount to be charged<strong> :</strong></div></td>
<td><input type="text" name="total"></td>
</tr>
<tr>
<td colspan="2"><div align="center"><strong>Notes</strong></div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<textarea name="notes" id="textarea"></textarea>
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<p>
<input type="submit" name="Submit" value="Send">
</p>
</div></td>
</tr>
</table>
</form>
</div>
</body>
</html>

david_ross 06-30-2004 02:13 PM

Try using:
fwrite($contact_db, $_POST["firstname"]."\r\n");

Rather than:
fwrite($contact_db, $firstname."\r\n");

If it works for firstname then try it for the othe variables.

Savahn 06-30-2004 02:31 PM

That worked. Thanks for help.

Savahn 06-30-2004 02:36 PM

That did work for the contact.txt file but the email is still blank.

david_ross 06-30-2004 02:37 PM

You will need to replace the variable names there too. For instance $name becomes $_POST["name"]

Savahn 06-30-2004 02:42 PM

When I do that I get and error on the page saying

Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/cc2/submit.php on line 91

david_ross 06-30-2004 03:11 PM

That is because you are surrounding the value in quotes too. Either use single quotes or:
".$_POST["name"]."

inplace of:
$name

Savahn 06-30-2004 03:15 PM

Thanks for help it works.


All times are GMT -5. The time now is 08:35 AM.