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 #177741 is a reply to message #177733] Thu, 19 April 2012 10:51 Go 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>

Hipa, "exclude the php code from this page" didn't make sense here.
However, you can separate php stuff by building function within the
individual page and then call that function 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: Sat Oct 05 06:13:24 GMT 2024

Total time taken to generate the page: 0.04280 seconds