I have a table lecturer with a column name and another department. I know for sure that one of the entries is name='Denis' and department='007'. This is the code:
<?php
$names; $surname;
require_once('connect_db.php');
$firstname = pg_query(connect(), "SELECT name FROM keep_track");
while($row = pg_fetch_array($firstname)){ $names = $row['path']." ".$row['name']; }
$lastname = pg_query(connect(), "SELECT surname FROM keep_track");
while($row = pg_fetch_array($lastname)){ $surname = $row['path']." ".$row['surname']; }
echo '<div id="show_dialog" class="ui-dialog-content ui-widget-content">';
echo "Lecturer: ".$names." ".$surname."<br>Department: ";
require_once('connect_db.php');
$a = pg_query(connect(), "SELECT department FROM lecturer WHERE name='$name'");
while($row = pg_fetch_array($a)){ echo "Hi!!!"; }
echo '</div>';
?>
But it doesnt echo anything. The variable $names has already been set and echoed in previous lines successfully and its value was set as John. The other queries Ive done are working fine. Idk why this one is not.
Update: OK, I know why it doesn't work, but idk how to fix it. The problem is in this line:
$a = pg_query(connect(), "SELECT department FROM lecturer WHERE name='$name'");
I need to compare column name with variable $name, but it won't work like that. What is the right syntax? I am looking, but i havent been very successful till now
SELECT FROMin your error message. The error message says you're missing the field(s) list in the query, but you clearly have them in your calls. So either this isn't the code causing the errors, or you've forgotten something while cutting/pasting.