Menu
well i got some php codes and tried to start using them. They didnt work… little did i know u needed a program to use PHP(or am i wrong?). Installed xampp… dont know what im doing… read the read me. got even more confused… tried messing around with it and now im totally confused.
Any suggestions? Do i need a program to use PHP or not? What am i doing wrong?
Now when i click a submit button that has action=”A.php” it sends me a download prompt.
[code=php]//formTarget.php
<?php
//check the $_POST variable for one of your form elements to see if the form has been submitted
if(isset($_POST["First_Name"])) { //then the form has been submitted
$filename = 'formtarget.txt'; //enter the real filename here
//construct a string to write into the file.
$somecontent = $_POST["First_Name"]."t".$_POST["Last_Name"]."n"; $_POST["State"]."n".
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
} [/code]
[code=php]<?php
$filename = 'test.txt';
$somecontent = "$_POST["First_Name"]n $_POST["Last_Name"]";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?> [/code]
[code=html]<html>
<head>
<title>TITLE</title>
</head>
<body>
<FORM METHOD=POST ACTION="http://localhost/PHPTEST.php">
<TABLE BORDER=0 WIDTH="75%" HEIGHT=90>
<TR>
<TD WIDTH=70>First Name</TD>
<TD width=120><INPUT TYPE="text" NAME="First_Name" SIZE="30"></td>
</TR>
<TR>
<TD WIDTH=70>Last Name</TD>
<TD WIDTH=120><INPUT TYPE="text" NAME="Last_Name" SIZE="30"></TD>
</TR>
<TR>
<TD WIDTH=70>Address 1</TD>
<TD WIDTH=120><INPUT TYPE="text" NAME="Address_1" SIZE="30"></TD>
</TR>
<TR>
<TD WIDTH=70>Address_2</TD>
<TD WIDTH=120><INPUT TYPE="text" NAME="Address_2" SIZE="30"></TD>
</TR>
<TR>
<TD WIDTH=70>City</TD>
<TD WIDTH=120><INPUT TYPE="text" NAME="City" SIZE="30"></TD>
</TR>
<TR>
<TD WIDTH=70>State</TD>
<TD WIDTH=120><SELECT NAME="State" SIZE="1">
<OPTION VALUE="AL"> Alabama
<OPYION VALUE="--">(I HAVE ALL THE STATES HERE BUT I FIGURED ID TAKE THEM OUT TO NOT ANNOY EVERYONE :)
<OPTION VALUE="WY"> Wyoming</SELECT></TD>
</TR>
<TR>
<TD WIDTH=70>Zip/Postal Code</TD>
<TD WIDTH=120><input type=text name="zip_code"></TD>
</TR>
<TR>
<TD WIDTH=70>Phone Number</TD>
<TD WIDTH=120><input type=text name="phone_no"></TD>
</TR>
</TABLE>
<INPUT TYPE="Submit" Value="Submit">
</form>
</body>
<html>[/code]
[code=php]
$somecontent = "$_POST["First_Name"]n $_POST["Last_Name"]";
// change it to this
$somecontent = "$_POST['First_Name']n $_POST['Last_Name']";
[/code]
No one is going to just write the script for you man! Those snippits that you copy and pasted from php.net are very good starting points to do what you want the code to do. Have you even tried them?[/QUOTE]
Well that's because both of them contain errors. Post the scripts and maybe someone can point them out.[/QUOTE]
0.1.9 — BETA 5.18