Jump to content


Photo

Forum help


  • Please log in to reply
2 replies to this topic

#1 mupets_revenge

mupets_revenge
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 March 2006 - 07:14 PM

right so the plan is to teach myself php and i though it was going well i seamed to be picking it up but have come up against a brick wall with this script.

The script is aimed to use a txt file like a database for a clan site. This is the submit section after we have played a match but i cant seam to get it to write to a file. The data then will be retreived again and posted on teh site through some more code which i am yet to write. It has to be txt as our host does not support mysql and such.

So all help is appreciated ...

So far have for the form page

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]</head>

<body>



<form name="form" method="post" action="submit.php">

<p>Type of match - Friendly, league, last minute or mess around </p>

<p>

<input type="text" name="textfield4">

</p>

<p>Opponents </p>

<p>

<input type="text" name="clan">

</p>

<p>Score</p>

<p>

<input type="text" name="score">

</p>

<p>Man of match</p>

<p>

<input type="text" name="manofmatch">

</p>

<p>Write up</p>

<p>

<textarea name="writeup"></textarea>

</p>

<p>&nbsp; </p>

<p>

<Input type="submit" name="submit" value="Wee" type="button">

</p>

</form>



</body>

</html>


[/quote]

then for submit.php have

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<? php
$type=$_POST['form'];
$Clan = $_REQUEST['clan'];
$score = $_POST['score'];
$manofmatch = $_POST['manofmatch'];
$writeup = $_POST['writeup'];



$fp = fopen("results.txt","a");

if(!$fp) {

print "error! The file could not be opened";

exit;

}



$stringtowrite=$Clan."|".$score."|".$manofmatch."|".$writeup."|".$type;



fwrite($fp, $stringtowrite);



fclose(fp);

Print "$clan" // this was an attempt to see if script was running it didnt print anything

?>

Done[/quote]


so how far wrong am i?

any help is appreciated and i am really sorry if i have made a big error as i have tried my best to use google to find me a solution to this but cant find anythin and its doing my head in.


#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 04 March 2006 - 03:15 AM

First, your test didn't work because:

Print "$clan";

because it is spelled $Clan when you made it...



#3 mupets_revenge

mupets_revenge
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 March 2006 - 08:36 AM

ok will change that thanks but can anyone tell me why it doesnt write to the results.txt file?

no matter i solved it

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR...ml4/loose.dtd">

<html>

<head>

<title>send results</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>



<form name="form" method="post" action="insert.php">

<p>Type of match - Friendly, league, last minute or mess around </p>

<p>

<input type="text" name="textfield4">

</p>

<p>Opponents </p>

<p>

<input type="text" name="clan">

</p>

<p>Score</p>

<p>

<input type="text" name="score">

</p>

<p>Man of match</p>

<p>

<input type="text" name="manofmatch">

</p>

<p>Write up</p>

<p>

<textarea name="writeup"></textarea>

</p>

<p>&nbsp; </p>

<p>


<input type="submit" name="Submit" value="Submit">
</p>

</form>



</body>

</html>





<?

}
[/quote]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php
$type=$_POST['type'];
$Clan=$_POST['clan'];
$score=$_POST['score'];
$manofmatch=$_POST['manofmatch'];
$writeup=$_POST['writeup'];

$fp = fopen("results.txt","r+");
if(!$fp) {
print "error! The file could not be opened";
exit;
}
$stringtowrite=$Clan."|".$score."|".$manofmatch."|".$writeup."|".$type;
fwrite($fp, $stringtowrite);
fclose($fp);
?>

Results submited[/quote]

was missing a php tag and a $ on the fclose function.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users