<?php



/* Config file */
include('config.php');

/* Connect to database & query */
if(isset($_POST['submit'])){

if($connectDatabase == TRUE){$action=TRUE;include('connect.php');}

$insertSQL = "INSERT INTO petitionlist (title, description, endtext, setting, owner) VALUES ('".$_POST['title']."', '".$_POST['description']."', '".$_POST['endtext']."', '".$_POST['setting']."','".$_POST['owner']."')";
$insertresult = mysql_query($insertSQL);

mysql_close();
}
if($connectDatabase == TRUE){$action=TRUE;include('connect.php');}

$query="SELECT * FROM petitionlist WHERE setting='active' ORDER BY id DESC" ;
$result=mysql_query($query);
$num=mysql_num_rows($result);

mysql_close();

include('header.php');

if($num!=0)
{
?>
<h1>all petitions</h1>
<table >
<tr>
<th>id</th>
<th>title</th>
<th>by</th>

<th></th>
</tr>

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"title");
$f3=mysql_result($result,$i,"owner");

?>

<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><a target="_blank" href="petition.php?id=<?php echo $f1; ?>">view</a></td>
</tr>

<?php
$i++;
}
}
?>


<?php

/* Disconnect from database */
if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}
?>

<?php
include('footer.php');
?>
