Creating .php Files

dont know if it is possible

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

39 Replies - 2765 Views - Last Post: 03 September 2002 - 01:51 PM Rate Topic: -----

#1 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Creating .php Files

Posted 26 August 2002 - 12:54 AM

ok what i am doing is, using a form to insert data into a database. now what i want to do is make is to that it pull the data off and creats a page using the title_name.php and uses a templete i set up for it. im using this for a gaming site so say i right a review for the game GTA3 i want it to pull the title row out of the database and create a .php using that title. and then on that php page making it so that all the rest of the data like the date and and the reveiw and rating and stuff are on that on the page. in the order i want it. how would i do something like that? if you need my code tell me i will post everything that i think will help you out.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating .php Files

#2 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 26 August 2002 - 01:25 AM

if your talking about creating a completely new file, technically fopen() would work.

although when I tried it I was told I didn't have the correct permissions to create the file. This may have been to do with the folder permissions though, I didn't check.

you would need something like this:

fopen ("/"$title_name/".php", w+);

http://www.php.net/m...ction.fopen.php
has more info
Was This Post Helpful? 0
  • +
  • -

#3 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 26 August 2002 - 09:18 AM

sorry, I was in a bit of a rush when I wrote the previous message, so it isn't too helpful. (or correct, at all :))

this should be a little more helpful:

$string = "content of the new file, i.e. /$review if it's an entry in the form.";

$file = "/"/$title_name/".php";

$fp = fopen("$file", "wb");
fputs($fp, $string);

fclose($fp);


Notes:
$title_name relates to the form field with the page name in it.
wb means it will attempt to open the file first, then create it if it does not exist (the 'b' shouldn't be needed but might be depending on your server)

it's always good practice to close files you've opened for various reasons :)

I believe you'll need to chmod the folder to '777' for the files to be created, so it might be a good idea to write all the files to a seperate folder.


Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#4 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: Creating .php Files

Posted 26 August 2002 - 07:21 PM

where would i put that code (im still new to php)
Was This Post Helpful? 0
  • +
  • -

#5 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 27 August 2002 - 02:18 AM

the code needs to go after the form code.

I used something similar to this on something I did and I put almost all of the php outside the </html> tag and it works fine.

if you need any more help, just ask :)
Was This Post Helpful? 0
  • +
  • -

#6 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: Creating .php Files

Posted 27 August 2002 - 12:09 PM

when i put it in i get this error

Warning: Division by zero in c:\foxserv\www\gamecube\reviews\tmp1j1lu1inyj.php on line 101

Warning: Division by zero in c:\foxserv\www\gamecube\reviews\tmp1j1lu1inyj.php on line 101

Warning: fopen("", "wb") - No error in c:\foxserv\www\gamecube\reviews\tmp1j1lu1inyj.php on line 103

Warning: Supplied argument is not a valid File-Handle resource in c:\foxserv\www\gamecube\reviews\tmp1j1lu1inyj.php on line 104

Warning: Supplied argument is not a valid File-Handle resource in c:\foxserv\www\gamecube\reviews\tmp1j1lu1inyj.php on line 106


how come?
Was This Post Helpful? 0
  • +
  • -

#7 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 27 August 2002 - 12:54 PM

I think thats cos you don't need to escape those symbols in this line:

$file = "/"/$title_name/".php";


you could try using

$file = "'/$title_name'.php";


instead.

oops :)
Was This Post Helpful? 0
  • +
  • -

#8 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: Creating .php Files

Posted 27 August 2002 - 01:09 PM

well i changed it to that and now im getting this error

Warning: fopen("'//'.php", "wb") - No such file or directory in c:\foxserv\www\gamecube\reviews\tmp3nttt1iqq2.php on line 62

Warning: Supplied argument is not a valid File-Handle resource in c:\foxserv\www\gamecube\reviews\tmp3nttt1iqq2.php on line 63

Warning: Supplied argument is not a valid File-Handle resource in c:\foxserv\www\gamecube\reviews\tmp3nttt1iqq2.php on line 65



if it helps this is the source to my form.

<?php require_once('../../Connections/conn.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO gc_reviews (id, title, genre, console, `date`, review, rateing, author, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['id'], "int"),
                       GetSQLValueString($HTTP_POST_VARS['title'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['genre'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['console'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['date'], "date"),
                       GetSQLValueString($HTTP_POST_VARS['review'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['rateing'], "int"),
                       GetSQLValueString($HTTP_POST_VARS['author'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['email'], "text"));

  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
}

mysql_select_db($database_conn, $conn);
$query_f = "SELECT * FROM gc_reviews";
$f = mysql_query($query_f, $conn) or die(mysql_error());
$row_f = mysql_fetch_assoc($f);
$totalRows_f = mysql_num_rows($f);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- start of .php creating code. -->
<? 
$string = "content of the new file, i.e. /$review if it's an entry in the form.";

$file = "'/$title/'.php";

$fp = fopen("$file", "wb");
fputs($fp, $string);

fclose($fp);
?>
<!-- end of .php creating code. -->
<html>
<head>
<title>Game Cube Review Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  Title: 
  <input name="title" type="text" id="title">
  <input name="id" type="hidden" id="id2">
  <br>
  Genre: 
  <input name="genre" type="text" id="genre">
  <br>
  Console 
  <input name="console" type="text" id="console">
  <input name="date" type="hidden" id="date" value"">
  <br>
  Review:<br>
  <textarea name="review" cols="100" rows="15" id="review"></textarea>
  <br>
  Rateing: 
  <input name="rateing" type="text" id="rateing" size="2">
  / 10<br>
  Author: 
  <input name="author" type="text" id="author">
  <br>
  Email: 
  <input name="email" type="text" id="email">
  <br>
  <br>
  <input type="submit" name="Submit" value="Submit">
  <input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($f);
?>


Was This Post Helpful? 0
  • +
  • -

#9 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 27 August 2002 - 01:40 PM

damn, i'm being really stupid :rolleyes: , you don't need the breaks at all in that bit...

that line should read:

$file = "'$title'.php";


should work then.
Was This Post Helpful? 0
  • +
  • -

#10 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: Creating .php Files

Posted 28 August 2002 - 08:23 AM

hey, that worked thanks, but now when i submit the stuff it goes into the data base, it created the file as 'title'.php how do i get rid of the ' in there and how would i link to it on the other page. like i have one page that lists all the reviews and i want it so you can click it and get to the review. so would i link it using something like this.
<a href src=<? echo $title ?>><? echo $title ?><\a>


Was This Post Helpful? 0
  • +
  • -

#11 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 28 August 2002 - 11:46 AM

damn, I can be *really* stupid sometimes :crazy:

you don't actually need the ' at all, I thought you did, but the dot stops the value :)

the line should read:

$file = "$title.php";


and if the $title is stored in your database with the .php extension your code is correct, otherwise you need to add in the .php

btw, you can write that line much neater like this:

<?php echo "<a href=$title>$title</a>"; ?>


or
<?php echo "<a href=$title.php>$title</a>"; ?>

if the database doesn't include the .php extension

P.S. if I've made any more mistakes I will shoot myself :)
Was This Post Helpful? 0
  • +
  • -

#12 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: Creating .php Files

Posted 28 August 2002 - 10:31 PM

ok here is a good question. ummm... how do i get the data into that page i created... right now it says "Page created by IE Form" or something along those lines.
Was This Post Helpful? 0
  • +
  • -

#13 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 29 August 2002 - 05:27 AM

I'm not quite sure what you mean...

is the code not writing the new page properly or what?

if so, did you chmod the directory to 777 so that new files can be created?
Was This Post Helpful? 0
  • +
  • -

#14 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: Creating .php Files

Posted 29 August 2002 - 08:42 AM

its creating the .php fine. but its not putting the content that i need in the form. like its only creating the page and when you open the page. it says something along the lines of "Page created with IE Form" and i want it so it shows the reviews the rating and shit like that.
Was This Post Helpful? 0
  • +
  • -

#15 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Creating .php Files

Posted 29 August 2002 - 11:52 AM

you know how you used the $title to create the file...

well you do something similar to insert the content.

the line you have as
$string = "content of the new file, i.e. /$review if it's an entry in the form.";


needs to be changed so that what goes inside the "'s is what you want your content to be.

so say if your form had the field $name and you wanted it to display

Name: Spider

you would put in
$string = "Name: $name";


basically you write the page contents in html, adding in the variables from the form where you want the content to be.

I hope that was clear enough :)
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3