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
php include, function, ... [message #177733] Wed, 18 April 2012 20:03 Go to previous message
hipa is currently offline  hipa
Messages: 5
Registered: March 2012
Karma:
Junior Member
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>
[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 04:23:06 GMT 2024

Total time taken to generate the page: 0.04907 seconds