a smal page making script.
07-09-2004, 09:17 PM
|
a smal page making script.
|
Posts: 62
Location: Norway, Bergen
|
Hello.
I have a script that gets some spsific lines from a webpage.
Quote:
<?php
$html=array_slice(file('http://aodb.info/showitem.asp?AOID=129045'),185,187);
foreach($html as $line)
echo "$line"
?>
|
What I need to do now, is to make a form, were I can write in "Name", "Title" and "URL". When I submit the form, it will save a page in my folder on my server with filnam the same as "Name"
So, if I type this in my form:
Name: test
Title: test1
URL: www.myserver.com/page5.php
..then I want a file saved on my server named test.php, looking like this:
Quote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body bgcolor="#9BAD8D">
<?php
$html=array_slice(file('www.myserver.com/page5.php'),185,187);
foreach($html as $line)
echo "$line"
?>
</body>
</html>
|
How can I do that?
The form:
Quote:
<body>
<form action="?????" method="POST or GET">
Name: <input type="text" name="name" size="20" maxlength="20" />
Title: <input type="text" name="title" size="20" maxlength="45" />
URL: <input type="text" name="url" size="20" maxlength="50" />
<input type="submit" value="Save page" />
</form>
</body>
</html>
|
I know I can us $_GET and so, and I know how to put in the link and title, but how do I save the file on my server, and how do I save it with the name?
|
|
|
|
07-10-2004, 08:32 AM
|
|
Posts: 62
Location: Norway, Bergen
|
Been working abit on this...
Why don't this work?
Quote:
<?php
$tittel = $_POST['tittel'];
$navn = $_POST['navn'];
$url = $_POST['url'];
$fp = fopen("http://www.housemaadiah.com/aoglinks/$navn.php","a+");
fputs($fp,"<html><head><title><?php echo $tittel ?></title></head><body><?php $_POST[$url] ?></body></html>");
fclose($fp);
?>
|
the folder "aoglinks" is chmod 777.
the form i use to give the data to this file is working as it should.
The error I get is:
Quote:
Warning: fopen(http://www.housemaadiah.com/aoglinks/.php): failed to open stream: HTTP wrapper does not support writeable connections. in /home/housemaa/public_html/save.php on line 7
Warning: fputs(): supplied argument is not a valid stream resource in /home/housemaa/public_html/save.php on line 8
Warning: fclose(): supplied argument is not a valid stream resource in /home/housemaa/public_html/save.php on line 9
|
|
|
|
|
07-10-2004, 07:36 PM
|
|
Posts: 62
Location: Norway, Bergen
|
New error.
save.php
Quote:
<?php
$tittel = $_POST['tittel'];
$navn = $_POST['navn'];
$url = $_POST['url'];
$page = "<html><head><title>TEST TEST TEST</title></head><body>huhuh</body></html>";
$fp = fopen("http://home.no.net/aogweb/test/aoglinks/$navn.php","a+");
fputs($fp,$page);
fclose($fp);
?>
|
error:
Quote:
Warning: fopen("http://home.no.net/aogweb/test/aoglinks/azure.php", "a+") - Success in /mnt/home3/a/ao/aogweb/public_html/test/save.php on line 8
Warning: Supplied argument is not a valid File-Handle resource in /mnt/home3/a/ao/aogweb/public_html/test/save.php on line 9
Warning: Supplied argument is not a valid File-Handle resource in /mnt/home3/a/ao/aogweb/public_html/test/save.php on line 10
|
|
|
|
|
07-10-2004, 08:04 PM
|
|
Posts: 136
|
HTTP connections are read-only; you cannot write data or copy files to an HTTP resource.
|
|
|
|
07-10-2004, 08:07 PM
|
|
Posts: 136
|
Use the full system path to the folder instead of http://
|
|
|
|
07-10-2004, 08:17 PM
|
|
Posts: 62
Location: Norway, Bergen
|
and how do I find the system path?
|
|
|
|
07-10-2004, 08:30 PM
|
|
Posts: 136
|
As you can see from your errors
Quote:
|
/home/housemaa/public_html/
|
is the path to your root folder.
so your needed path will be
Quote:
|
$fp = fopen("/home/housemaa/public_html/aogweb/test/aoglinks/$navn.php","a+");
|
|
|
|
|
07-11-2004, 12:14 PM
|
|
Posts: 62
Location: Norway, Bergen
|
Ok.
Now I have this form output:
Quote:
<?php
$type = $_POST['type'];
$name = $_POST['name'];
$ql = $_POST['ql'];
$link = $_POST['link'];
$nr = $_POST['nr'];
$price = $_POST['price'];
$bid = $_POST['bid'];
$bo = $_POST['bo'];
$href = ('<a href='."$link".' target="_blank">'."$name".'</a>');
if ($type == "Patterns:")
$fp = fopen("/mnt/home3/a/ao/aogweb/public_html/test/aoglinks/busskort.php","a+");
fputs($fp,'<html><head><title>Patterns.</title></head><body><table width="500" border="0">
<tr>
<td colspan="6"><strong>Patterns:</strong></td>
</tr>
<tr>
<td>Item:</td>
<td>QL:</td>
<td>Number of items:</td>
<td>Price per item:</td>
<td>Bid? y/n</td>
<td>BidOut:</td>
</tr>
<tr>
<td>'."$href".'</td>
<td>'."$ql".'</td>
<td>'."$nr".'</td>
<td>'."$price".'</td>
<td>'."$bid".'</td>
<td>'."$bo".'</td>
</tr>
</table></body></html>');
fclose($fp);
?>
|
Problem is that it will be saved like this:
Quote:
Patterns:
Item: QL: Number of items: Price per item: Bid? y/n BidOut:
Huhu 50 2 350k Yes 700k
Patterns:
Item: QL: Number of items: Price per item: Bid? y/n BidOut:
Azure Body 190 1 500k No n/a
|
..but I want it like this:
Quote:
Patterns:
Item: QL: Number of items: Price per item: Bid? y/n BidOut:
Huhu 50 2 350k Yes 700k
Azure Body 190 1 500k No n/a
|
|
|
|
|
07-11-2004, 03:11 PM
|
|
Posts: 136
|
Quote:
<?php
$type = $_POST['type'];
$name = $_POST['name'];
$ql = $_POST['ql'];
$link = $_POST['link'];
$nr = $_POST['nr'];
$price = $_POST['price'];
$bid = $_POST['bid'];
$bo = $_POST['bo'];
$href = ('<a href='."$link".' target="_blank">'."$name".'</a>');
if ($type == "Patterns:")
$fp = fopen("/mnt/home3/a/ao/aogweb/public_html/test/aoglinks/busskort.php","a+");
fputs($fp,'<tr>
<td>'."$href".'</td>
<td>'."$ql".'</td>
<td>'."$nr".'</td>
<td>'."$price".'</td>
<td>'."$bid".'</td>
<td>'."$bo".'</td>
</tr>
</table></body></html>');
fclose($fp);
?>
|
This part should be taken out of the script:
Quote:
<html><head><title>Patterns.</title></head><body><table width="500" border="0">
<tr>
<td colspan="6"><strong>Patterns:</strong></td>
</tr>
<tr>
<td>Item:</td>
<td>QL:</td>
<td>Number of items:</td>
<td>Price per item:</td>
<td>Bid? y/n</td>
<td>BidOut:</td>
</tr>
|
Make some checking of the file size and if the file size is 0 then add that part to the beginning. If the file already has some records, then the size will be more than zero and you don't need to add that part.
|
|
|
|
07-11-2004, 07:05 PM
|
|
Posts: 62
Location: Norway, Bergen
|
What/how can I edit the busskort.php?
I.E. I want to write ower and not add if the $href allready exists in the busskort.php
|
|
|
|
07-11-2004, 08:11 PM
|
|
Posts: 136
|
Why you don't want to use mysql and create all your pages on the fly?
It will increase the performance of your site. And you can do anything with your data.
|
|
|
|
07-11-2004, 08:21 PM
|
|
Posts: 62
Location: Norway, Bergen
|
hehe... MySQL? ...and I am a n00b on php.
hehe.. want to show? 
|
|
|
|
07-11-2004, 08:45 PM
|
|
Posts: 136
|
I'll show it tomorrow to you 
Have to run away now.
|
|
|
|
07-11-2004, 08:52 PM
|
|
Posts: 62
Location: Norway, Bergen
|
cool
I thank you for your great help so far 
|
|
|
|
07-12-2004, 09:36 AM
|
|
Posts: 136
|
Ok.
So, all you have to do its to create the database for your items in mysql. With all reqired fields. Or create two table relevant to each other.
After that take the variables from your form and put it in your database.
And when you need to display the pages, just take the data from the database.
PHP Code:
//Connect to your database:
$connect = mysql_pconnect($hostname, $username,
$password) or trigger_error(mysql_error(),
E_USER_ERROR);
//Insert in your database:
$insertSQL = "INSERT INTO items (name, detail1,
detail2) VALUES ('$name', '$details1','$details2')";
mysql_select_db("yourdatabasenamehere", $connect);
$Result = mysql_query($insertSQL, $connect) or
die(mysql_error());
Try to learn more about php+mysql. 
|
|
|
|
07-12-2004, 10:13 AM
|
|
Posts: 62
Location: Norway, Bergen
|
oki.. My host have this thing were I can make the data base.
What I have now is:
Fields: "the name of my fields"
Type: TEXT
Length: "what I need for each fields".
Attirbutes: here is my question. I can choose "BINARY", "UNSIGNED", "UNSIGNED ZEROFILL". What should I choose?
Null: I can choose "null" and "not null" What should I chose?
Standard: Here I can type what I want. What does it do?
Then I must choose (for each fields), Primary, Index, Unik, ---, Fulltext. What do I choose?
Allsow I can choose what type the tabell should be. "Standard", "MyISAM", "Heap", "Merge", "ISAM". What do I choose?
Last edited by aog : 07-12-2004 at 10:18 AM.
|
|
|
|
07-12-2004, 03:25 PM
|
|
Posts: 62
Location: Norway, Bergen
|
oki.. ignore the last post
What I have now, is a db called "housemaa_items".
In that db I have 2 tables called "Patterns" and "Armor"
"Patterns" have 6 fields. id, Items:, Ql:, Price:, Bided price:, Bided by:.
"Armor" have 6 fields. id, Items:, Ql:, Price:, Bided price:, Bided by:.
Now I need a form output to insert data to the tabel. (The form I can make)
But how do I connect to the database and to the table "Patterns"?
|
|
|
|
07-13-2004, 06:56 AM
|
|
Posts: 130
|
I am kind of new to this, but i dont understand what you are trying to do? Are you trying to create a page whereby you can input data, or are you trying to output the data in the table to a page on your site? ...or neither?
Andy
|
|
|
|
07-13-2004, 08:51 AM
|
|
Posts: 62
Location: Norway, Bergen
|
What I'm trying to do, or I should say what I tried to do was to make a php script were I could easy write in new info, and edit info.
Then I found out it whould be easyer with a databse, so now I'm trying to learn mySQL.
It's not going to well, couse I cant realy find any good guides on the net.
The ressult of my database will be a database with "Items" I want to sell or auction away. I want peoples to be able to bid on a item, and I want my selfe to be able to delete a item, or just change satus of it.
Later on I will perhaps make a new or make this one better, so that pll can register and add items them selfe. but thats not main objective.
What I have so far, is a database with a table in.
What I now need to know, is how do I write to on spesific table and a spesific row in that table?
I can easy make tha form, but how do I "conncet" to the table and stuff..?
Thats my question atm... 
|
|
|
|
07-13-2004, 09:14 AM
|
|
Posts: 130
|
Hi. I will describe mine at the moment which is a form where i can add a persons details but this can be edited to anything that you want.
Here is the add.html file
HTML Code:
<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit">
</form>
Now insert.php. Of course you can change the variables to fit in with your own table. Here it is
PHP Code:
<?
include("dbinfo.inc.php");
mysql_connect("69.49.230.13",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES (",'$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);[/color]
mysql_close();
?>
The $query bit in you must change to your own details like $price and bidprice$ or whatever your fields are called in your table.
Inside the insert.php file there is another php file called dbinfo.inc.php which needs to have your login information put into it
PHP Code:
<?
$username="????????";
$password="????????";
$database="??????????";
?>
This is what this forum helped me set up, so hopefully it is what you are after and you can adapt it to fit your situation. Any questions i will try help, but I have only just started php
Mysql is so good though, I have been using it for 3 days and I already feel like almost anything is possible with it!
Andy
|
|
|
|
|
« Reply to a smal page making script.
|
|
|
|