Hey
Im trying to merge these two pieces of code and im really struggling to get it worknig!
Its a add.php file that adds a user to a database, and then I want it to create a file with the name $username.php and insert the field "supplier1" into the file.
Here is the add.php:
<?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 dbSuppliers (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 supplier 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";
}
?>
Here is the file creation code:
$supplierinfo = mysql_query("select * from dbSuppliers WHERE username=\"$username\"");
while($r1=mysql_fetch_array($supplierinfo)){
extract($r1);
$username = "$POST[\"username\"]";
$filename= "$username.php"
$supplier1 = "$POST[\"supplier1\"]";
if (is_writable($filename)) {
if (!$handle = fopen($username, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $supplier1) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote the content to file ($filename)";
fclose($handle);