Jump to content

fwrite() and location in a file


illuz1on

Recommended Posts

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

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);

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.