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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.