/    Sign up×
Community /Pin to ProfileBookmark

Auto-generate html page with content.

Forgive me in advance if this is hard to follow. I know I’ve been taking serious advantage of these boards and all of you fantastic people already. Wish I could have a programmer stand over my shoulder as a screw up!

[B]The Goal:[/B]

Enter a news item into a form that writes to a database (fields: id, date, headline, leadin, story). [COLOR=Red]check![/COLOR]
Auto-forward to a php script (makepage.php) which will auto-generate an html page based on ‘id’ and output ‘story’ (in a stylized page). [COLOR=Red]Not Quite check![/COLOR]

Display ‘date’, ‘headline’, ‘leadin’ on a separate page, and have ‘headline’ link to that url that was created in makepage.php. [COLOR=Red]Mostly check![/COLOR]

[B]The Problem:[/B]

I am able to generate that html page, and even get it to display the story from the database along with a headline, etc. But I get an error when I process my makepage.php. I think that I’ve just improvised code that happened to work occasionally.

[B]All Ready?[/B]

[code=php]<?php

$database=”newsadmin”;
$username=””;
$password=””;

mysql_connect(localhost,root);
@mysql_select_db($database) or die( “Unable to select database”);

$query=”select * from news ORDER BY ‘id’ DESC”;
$result=mysql_query($query);

$i=0;
while ($i < 1){
$id=mysql_result($result,$i,”id”);
$date=mysql_result($result,$i,”date”);
$headline=mysql_result($result,$i,”headline”);
$story=mysql_result($result,$i,”story”);

$selfgen=”news/$id.html”;

$filename=”$selfgen”;
$filehandler=fopen($filename, ‘w’) or die(“can’t open file”);

$stringData = “<body style=”background-color: #E8E8D0; font-family: arial, helvetica, sans-serif; font-size: 12px;
margin: 100px”>
<div style=”font-weight: bold; font-size: 14px”>$headline</div><br>
<div style=”font-weight: bold;”>$date</div><br>
$story</body>n”;
fwrite($filehandler,$stringData);

fclose($filehandler);
}

?>[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@miyaka_sheilaFeb 06.2006 — HELP Please....

Hi.. Im a newbie in web design and almost Zero on php scripting. Cna any one help me or give me a simple script for my sample database?

My database has 5 fields : "ID" - key and VAR1, VAR2, VAR3, VAR4

What i want to do is :
>>> Have a form field that would ask me to encode content of VAR1 <<<<

after i press submit

>>> New page or same page will ECHO me contents of VAR1 and VAR2

and also ask me to encode/input for VAR3...

>>> If my input in VAR3 is correct (somewhat like password checking) The databse should show me the contents of VAR4...


Please if anyone can give me PHP script of this...

Please ask if you need clarifications...

-Shiela
Copy linkTweet thisAlerts:
@chazzyFeb 06.2006 — Forgive me in advance if this is hard to follow. I know I've been taking serious advantage of these boards and all of you fantastic people already. Wish I could have a programmer stand over my shoulder as a screw up!
[/QUOTE]


Maybe, so I can understand why you're doing this, but why are you doing this? You're kind of defeating the purpose of a database. It would be much easier to have viewpage.php?id=3 as far as displaying, editting, and maintaining goes. So if you could please, explain why this approach?

But anyways, as far as fixing your problem, what error are you getting? I can see 2-3 problems with the code you have.

[list]
  • [*]don't use mysql_result to get results.

  • [*]it's much easier, with the way you're doing it, to use while($row=mysql_fetch_assoc($resource)). Then the different elements would be $row['element_name']

  • [*]and then my notes from above.

  • [/list]
    Copy linkTweet thisAlerts:
    @calliepeckauthorFeb 06.2006 — I'm doing it this way because I've been trying to give myself a super crash-course in SSL and couldn't think of any other options. Your way sounds much better--anything in the way of a 'for dummies' tutorial that would achieve what I need?
    Copy linkTweet thisAlerts:
    @chazzyFeb 06.2006 — Not that I know of. You can search on phpbuilder.com they should have something, but it's fairly simple. Basically you need to read the query string (?id=3) [this is done via the[URL=http://www.php.net/variables.predefined]$_GET[/URL] array(this is done by using: [code=php]$id=$_GET['id'];[/code]). Then you would perform your sql much the same way, except you would only select the row associated with the current $id. Then just print out the array in question using the same method I described or using your method (except no while loop.)
    Copy linkTweet thisAlerts:
    @calliepeckauthorFeb 07.2006 — I'm sorry, I'm completely lost here. Can anyone help me put this in context?

    Thanks again.
    Copy linkTweet thisAlerts:
    @chazzyFeb 07.2006 — Well, what is your status. Do you need to learn PHP?
    Copy linkTweet thisAlerts:
    @calliepeckauthorFeb 07.2006 — I understand the components of php enough to write to and read from a database and create very simple functions. The problem is finding a resource that bridges the gap between a beginner knowledge and advanced coding. The first time I looked at PHP was maybe a week ago, so I'm still on shaky grounds but could get up to speed quickly with a good runthrough of intermediate coding. I get lost in the official PHP manual.
    Copy linkTweet thisAlerts:
    @chazzyFeb 07.2006 — I'd recommend one of the O'Reilly books on learning PHP then, if you're willing to buy a book. Otherwise, phpjournal.com is pretty good. I learned off of a book and trial and error.
    Copy linkTweet thisAlerts:
    @cwilkeyFeb 07.2006 — I couldn't agree with chazzy more...I think that your making this way more complicated than it needs to be. I bought the O'Reilly books when I first started to learn PHP. I mostly use them for reference. The majority of my skills where self taught from trial and error - and not to mention, the use of WONDERFUL boards such as this one.

    Hang in there...
    ×

    Success!

    Help @calliepeck spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.15,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...