I try to select data table from pg_admin4 but it's not work.
Here my code - file: index.php
<DOCTYPE html>
<head>
<title>Accounting for the execution of tasks</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1 style="color:rgb(187, 91, 74); text-align:center">Projects Database</h1>
<hr></hr>
<h2>List actions:</h2>
</body>
</html>
<?php
$dbuser = 'postgres';
$dbpass = 'thien123';
$host = 'localhost';
$dbname='data_main';
$dbschema='data1';
$db = pg_connect("host=$host dbname=$dbname user=$dbuser password=$dbpass") or die("Couldn't connect: ". pg_last_error());
//$query = "INSERT INTO imployee VALUES ('$_POST[id_imployee]', '$_POST[book_name]')";
//$result = pg_query($query);
//pg_close($db);
?>
<html>
<h3> Select a table </h3>
<form method = "POST" action="">
<select name="select_db" >
<option value="None"> Select a table </option>
<?php
$query = "select * from information_schema.tables
where table_schema = 'data1' and table_type = 'BASE TABLE'
order by table_name;";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
while($row = pg_fetch_assoc($result)):
?>
<option value="<?php echo $row['table_name']; ?>">
<?php echo $row['table_name']; ?></option>
<?php endwhile; ?>
</select>
<input type="submit" name="submit">
</form>
</html>
<?php
$table = $_POST["select_db"];
if(isset($table) && $table != 'None')
{
echo "<p><b><i> $table </i> table</b></p>";
$query = "select * from \"$table\"";
$result = pg_query($query) or die('Error! '. pg_last_error());
$i = 0;
echo '<style>
table, th, td
{
border: 1px solid black;
}
</style>';
echo '<html><body><table><tr>';
while ($i < pg_num_fields($result))
{
$field_name = pg_field_name($result, $i);
echo '<td>' . $field_name . '</td>';
$i++;
}
echo '</tr>';
$i = 0;
while ($row = pg_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$r = 0;
while ($y < $count)
{
$cur_row = current($row);
echo '<td>' . $cur_row . '</td>';
next($row);
$r++;
}
echo '</tr>';
$i++;
}
pg_free_result($result);
echo '</table></body></html>';
}
?>
when i run it in browser, i get error
Query failed: ERROR: relation "imployee" does not exist LINE 1: select * from "imployee" ^
error when i chose the table employee
here the query i did in pg admin4
i use xammpp 8.0.6
i don't know how to fix it.