FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php include, function, ...
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: php include, function, ... [message #177740 is a reply to message #177733] Thu, 19 April 2012 10:55 Go to previous messageGo to previous message
IRC is currently offline  IRC
Messages: 6
Registered: April 2012
Karma:
Junior Member
On Apr 18, 9:03 pm, hipa <hipa.inva...@telenet.be> wrote:
> Hi there
>
> I have a litle page with a form, which inserts an article in a postgres
> db with php.
> The php code is in the html page. Can someone tell me what the best way
> is to exclude the php code from this page. And then just calling it true
> a function or something?
>
> <body>
> <?php
> if(isset($_POST['insertarticle']) && $_POST['insertarticle']){
>      $dbh = pg_connect("host=..... dbname=..... user=.....
> password=.....");
>      if (!$dbh) {
>          die("Error in connection: " . pg_last_error());
>      }
>
> if(isset($_POST['article'])){
> $article = pg_escape_string($_POST['article']);
> $sql = "INSERT INTO tblarticle values ((select max(idarticle) + 1 from
> tblarticle), '{$article}')";
> $result = pg_query($dbh, $sql);}
>
> {die(pg_last_error());}
>
> if (!$result) {
>          die("Error in SQL query: " . pg_last_error());
>      }
> pg_free_result($result);
> pg_close($dbh);}
>
> ?>
>
> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
> <input type="submit" name="insertarticle" value="Insert Article">
> <label>Article:</label> <input id="article" name="article" type="text">
> </form>
> </body>

"exclude the php code from this page" didn't make any sense, but, if
you would like to separate the php code from html page, better write
all the php stuff in one page and including it into the required area
or you make create a function and call it wherever you like.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Weird behaviour when adding values to associative arrays
Next Topic: Date/Time warning
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 00:01:55 GMT 2024

Total time taken to generate the page: 0.04206 seconds