I am developing a website using XHTML and PHP forms to allow a user to query a Postgre SQL database table. The database table contains a list of games, which the user should be able to view and query, in order to display just the games between any price range that the user specifies.
Currently, I have three pages: index.php, home.php and gamesByPrice.php
When the user initially browses to the website, they are taken to the index.php page, where they are asked to log in. Once they have logged in, they are taken to the home.php page, which displays a welcome message, and tells the user how many games there are currently stored in the database table, also displaying a full list of those games, along with their price and description in an XHTML table.
I then have a simple form, which the user can use to search for any games between any price range that they specify. When I enter values into the minimum and maximum price range text boxes, I am then taken to the gamesByPrice.php page, which should display the search results, currently however, it is just returning the error message below:
Code: Select all
if(!$dbconn){ die('Could not connect: ' . pg_error()); } 1Welcome !!
Warning: pg_query() [function.pg-query]: Query failed: ERROR: column "minprice" does not exist LINE 2: WHERE price>=minPrice && price<=maxPrice ^ in /berw/ugrad1/base/e/eef8/public_html/cs25010/gamesByPrice.php on line 42
Error in query: SELECT title, price, description FROM CSGames WHERE price>=minPrice && price<=maxPrice.ERROR: column "minprice" does not exist LINE 2: WHERE price>=minPrice && price<=maxPrice ^
Code: Select all
<?php
session_start();
// retrieve stored session data
$_SESSION['userName']=$_POST['userName'];
?>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Home</h1>
<?php
// retrieve session data
echo "Welcome ".$_SESSION['userName']."!";
?>!
<p><br /></p>
<?php
echo extension_loaded('pgsql');
$conn_string = "host=***** port=**** dbname=***** user=***** password=*****";
$dbconn = pg_connect($conn_string);
if(!$dbconn){
die('Could not connect: ' . pg_error());
}
// generate and execute a simple query to check that the php script is connecting
// to the database, and that SQL queries will return required data
$query = "SELECT * FROM CSGames";
$result = pg_query($dbconn, $query) or die("Error in query: $query." . pg_last_error($dbconn));
// Get the number of rows in the resultset
$rows = pg_num_rows($result);
echo "\n There are currently $rows games in the database.";
?>
<p><br /></p>
<h1>Search for games by price: </h1>
<p>Enter price range of games you would like to search for:</p>
<form action="gamesByPrice.php" method="post">
Miniumum price: <input type="text" name="minPrice" />
Maximum price: <input type="text" name="maxPrice" />
<input type="submit" value="Search" />
</form>
<?php
// This stores the values that the user entered for min and max price, so that
// a user can search for games by any particular price range.
$_SESSION ['minPrice']="minPrice";
$_SESSION ['maxPrice']="maxPrice";
?>
<?php
// query to retrieve titles of all games from database, with their price and description
$gameTitlesQuery = "SELECT title, price, description FROM CSGames";
$gameTitlesQueryResult = pg_query($dbconn, $gameTitlesQuery) or die("Error in query: $gameTitlesQuery." . pg_last_error($dbconn));
?>
<?php
echo '<div id="Games">';
echo '<table id="Games" border="1">';
while ($a=pg_fetch_row($gameTitlesQueryResult)){
echo '<tr>';
for ($i=0; $i<pg_num_fields($gameTitlesQueryResult); $i++){
echo '<td>'.htmlspecialchars($a[$i], ENT_QUOTES).'</ td>';
}
echo "<td><input type='checkbox' name='selectGame' value='{$a['refnumber']}' /></ td>
</ tr>";
}
echo '</table></ div>';
?>
</body>
</html>
Code: Select all
<?php
session_start();
// retrieve stored session data
$_SESSION['userName']=$_POST['userName'];
$_SESSION['minPrice']=$_POST['minPrice'];
$_SESSION['maxPrice']=$_POST['maxPrice'];
?>
<html>
<head>
<title>Games Search By Price</title>
</head>
<body>
<h1>Search Results</h1>
if(!$dbconn){
die('Could not connect: ' . pg_error());
}
<?php
echo extension_loaded('pgsql');
$conn_string = "host=***** port=**** dbname=***** user=***** password=*****";
$dbconn = pg_connect($conn_string);
// retrieve session data
echo "Welcome ".$_SESSION['userName']."!";
?>!
<?php
// To get the query below to work, I will need to store the values the user entered
// for minimum and maximum price in PHP variables, and then retrieve them on
// this page
// query to retrieve titles of all games from database, whose price is between a certain range, with their price and description
$gameTitlesByPriceQuery = "SELECT title, price, description FROM CSGames
WHERE price>=minPrice && price<=maxPrice";
$gameTitlesByPriceQueryResult = pg_query($dbconn, $gameTitlesByPriceQuery) or die("Error in query: $gameTitlesByPriceQuery." . pg_last_error($dbconn));
?>
<p><br /></p>