illuz1on Posted April 17, 2007 Share Posted April 17, 2007 Hey... This is my add.php ... I want it to create a file with the name: $username.php every time a user is added, but I cannot figure it out.. Can anyone help me? I know its with fwrite() but i dont know where in here to put it Thanks alot !! <?php include ("dbConfig.php"); if ( $_GET["op"] == "reg" ) { $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "") { $bInputFlag = false; } else { $bInputFlag = true; } } if ($bInputFlag == false) { die( "Problem with processing of information. " ."Please go back and try again"); } $q = "INSERT INTO `dbGrowers` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; $r = mysql_query($q); if ( !mysql_insert_id() ) { die("Error: User not added to database..."); } else { Header("Location: add.php?op=success"); } } elseif ( $_GET["op"] == "success" ) { echo "<h2>The grower has been added successfully...</h2>"; } else { echo "<form action=\"?op=reg\" method=\"POST\">\n"; echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n"; echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n"; echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n"; echo "<input type=\"submit\">\n"; echo "</form>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/47453-fwrite-and-location-in-a-file/ Share on other sites More sharing options...
rpadilla Posted April 17, 2007 Share Posted April 17, 2007 use fopen first, http://php.net/fopen Link to comment https://forums.phpfreaks.com/topic/47453-fwrite-and-location-in-a-file/#findComment-231551 Share on other sites More sharing options...
illuz1on Posted April 17, 2007 Author Share Posted April 17, 2007 must i put it in where it says ------ OVER HERE ------------- below? if ($bInputFlag == false) { die( "Problem with processing of information. " ."Please go back and try again"); } ------ OVER HERE ------------- $q = "INSERT INTO `dbGrowers` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; $r = mysql_query($q); Link to comment https://forums.phpfreaks.com/topic/47453-fwrite-and-location-in-a-file/#findComment-231556 Share on other sites More sharing options...
illuz1on Posted April 17, 2007 Author Share Posted April 17, 2007 ok well lemme put it this way I want to merge this piece of code (dont know if its working yet) into the code in the original post.. <?php include("dbconnect.php"); $supplierinfo = mysql_query("select * from dbSuppliers WHERE username='$username'"); while($r=mysql_fetch_array($supplierinfo)){ extract($r); $myFile = "$username.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$supplier1\n"; fwrite($fh, $stringData); $stringData = "$supplier2\n"; fwrite($fh, $stringData); fclose($fh); ?> Link to comment https://forums.phpfreaks.com/topic/47453-fwrite-and-location-in-a-file/#findComment-231576 Share on other sites More sharing options...
rpadilla Posted April 17, 2007 Share Posted April 17, 2007 I'm not sure if using fwrite twice would work, but anyway just try it, if it won't work, just use 1 fwrite, still just go to www.php.net/fwrite cheers. Link to comment https://forums.phpfreaks.com/topic/47453-fwrite-and-location-in-a-file/#findComment-231606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.