The code was designed to create a new page with the random number and then it would insert code into the newly created file. This worked when I was using my localhost, but now I receive these error messages. I looked around the web and I saw somethings about permissions??? So, please be as detailed as possible in your answer!
I get this error for this code.....

Warning: fopen(964830301.php) [function.fopen]: failed to open stream: Permission denied in product.php on line 168
PHP Error Message
Warning: fwrite(): supplied argument is not a valid stream resource in product.php on line 169

This is the code...

$Random_Number = rand(100,100000000000);
$Check_Number = mysql_query("SELECT * FROM products WHERE randomnumber='$Random_Number'");
$Check_Final = mysql_num_rows($Check_Number);

while($Check_Final != '0')
{
    $Random_Number = rand(100,100000000000);
}

$Query = mysql_query("INSERT INTO products (title,url,finalurl,category,owner,shortdescription,price,rank,tag1,tag2,tag3)
                      VALUES ('$Title','$Random_Number','$url','$Category','$Username','$SD','$Price','-10','$Tag1','$Tag2','$Tag3')");
echo mysql_error();
if(!$Query)
{
    die("There was an error creating your product!");
}
else
{
    echo "Yes! Your product was created, I hope " . $Title . " will rank high!";
    $Insert_Link_Click = '0';
}

$php = "<?php

if (!mysql_connect(\"127.0.0.1\",\"root\",\"\"))
  {
  die(\"MySQL could not connect!\");
  }

if(!mysql_select_db('FinddOnline'))
{
die(\"My SQL could not select Database!\");
}
\$Today = date(\"Y-m-d\");
if(!mysql_query(\"INSERT INTO clicks (username,title,date)
                      VALUES ('$Username','$Title','\$Today')\"))
{
    die(\"Opps Try again!\");
}
else
{
header(\"location:$url\");
}
                      

?>";

$Create_File = fopen($Random_Number . '.php','w');
fwrite($Create_File,"$php");

?>

Recommended Answers

All 5 Replies

Okay, the error your getting means that fopen can't open the file you're requesting because the permissions of that file (or directory) won't allow it.

If you're server is on Linux:
From the shell cd to the directory where that file resides, and issue

chmod 777 *

This will give you full read/write/execute permissions to all files in the directory, and prevent the error from occurring again.

If you're running your site from a web host, check with them for how to change your permissions.

Yea I don't know what I'm using?? I'm just using the web host 000webhost.com

Okay, go to your FTP access to browse your directories, then in the left panel there should be a link for permission settings. Tick all the boxes

I don't have a left panel?

Go to your cPanel, under the Files tab click 'Another File Manager'. Click through public_html directory, click a file or directory ONCE, then in the left panel there IS a permissions option. I'll leave it up to you to decide which files you will want to use file handles on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.