|
Post by splatcatballa99 on Apr 24, 2007 21:27:20 GMT
Ok i think i succesfully wrote a script that submits data to a flat file but i'm not sure? i open the flatfile and i see no info or anything? heres the 2 files i have for the registration process.. <html> <head> <title></title> </head>
<body bgcolor="#FFFFFF"> <table> <tr> <td> <form name="reg" method="post" action="register2.php"> Username: </td> </tr> <tr> <td><input type="text" name="username" value=""> </td> </tr> <tr> <td> Password: </td> </tr> <tr> <td><input type="text" name="password" value=""> </td> </tr> <tr> <td> Email: </td> </tr> <tr> <td> <input type="text" name="email" value=""> </td> </tr> <tr> <td> First Name: </td> </tr> <tr> <td><input type="text" name="fname" value=""> </td> </tr> <tr> <td> Last Name: </td> </tr> <tr> <td><input type="text" name="lname" value=""><br /><input type="submit" value="Submit"> </form> </td> </tr> </table>
</form> </body>
</html>
Heres the PHP to handle it... <html> <head> <title></title> </head>
<body bgcolor="#FFFFFF"> <php if (isset($_POST['submit'])) {
$username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $fname = $_POST['fname']; $lname = $_POST['lname'];
$fp = fopen("userdata.txt","a"); if( !fp ) { echo "There was an error writing the data please try again."; exit; } fwrite ($fp, $username."||" $password."||" $email."||" $fname."||" $lname."\n"); fclose($fp); } readfile ("userdata.txt"); ?> </body>
</html>
I even tried readfile("userdata.txt"); and it returned nothing. anyone have any ideas?
|
|
|
Post by Graeme on Apr 24, 2007 21:34:53 GMT
Right, theres a problem with your IF statement. if( !fp ) { echo "There was an error writing the data please try again."; exit; } Should be... if( !$fp ) { echo "There was an error writing the data please try again."; exit; } Also i would suggest doing this: if($fp = fopen("userdata.txt","a")) { fwrite ($fp, $username."||" $password."||" $email."||" $fname."||" $lname."\n"); fclose($fp); } else{ echo "There was an error writing the data please try again."; exit; }
Adding the else part to the code. Hope this helps.
|
|
|
Post by splatcatballa99 on Apr 24, 2007 21:44:36 GMT
hmm i get this Parse error: syntax error, unexpected T_VARIABLE in /home/dkraklan/public_html/phptesting/register2.php on line 22
and ehres teh code <?php if (isset($_POST['submit'])) {
$username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $fname = $_POST['fname']; $lname = $_POST['lname'];
$fp = fopen("userdata.txt","a"); if( !$fp ) { echo "There was an error writing the data please try again."; exit; } fwrite ($fp, $username. "||" $password. "||" $email. "||" $fname. "||" $lname. "\n" ); fclose($fp); } readfile ("userdata.txt"); ?>
|
|
Tobias
New Member
CSS Master
Rave like there's no tomorrow..
Posts: 39
|
Post by Tobias on Apr 24, 2007 21:46:52 GMT
fwrite ($fp, $username. "||". $password. "||". $email. "||". $fname. "||". $lname. "\n" ); You forgot a few dots.
|
|
|
Post by Graeme on Apr 24, 2007 21:47:08 GMT
Nevermind, beaten to it...
|
|
|
Post by splatcatballa99 on Apr 24, 2007 21:58:10 GMT
ok i got that fixed and now i have
<?php if (isset($_POST['submit'])) {
$username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $fname = $_POST['fname']; $lname = $_POST['lname'];
$fp = fopen("http://www.kraklak.com/phptesting/userdata.txt","a"); if( !$fp ) { echo "There was an error writing the data please try again."; exit; } fwrite ($fp, $username."||" .$password."||". $email."||" .$fname."||". $lname."\n"); fclose($fp); } ?>
but no data is being written to the userdata.txt file.
|
|
Tobias
New Member
CSS Master
Rave like there's no tomorrow..
Posts: 39
|
Post by Tobias on Apr 24, 2007 22:57:05 GMT
|
|
|
Post by [dmsuperman] on Apr 25, 2007 1:33:15 GMT
I'm not sure you can pass a URL as the file statement for fopen if you're going to be writing to it. I would try just fopen("userdata.txt", "a"); if it's in the same folder.
|
|