Jump to content

mystery error on line 3


happygolucky

Recommended Posts

<html>
    <head><title>Media Mart</title>
    </head>
        <body>
            <p>Search Media Mart:<br />
                <form action="index.php" method="post">Keyword:<br />
                <input type="text" name="keyword" size="20" maxlength="40" value="" /><br />Field:<br />
                    <select name="field">
                        <option value="">Choose field:</option>
                        <option value="artist_name">Artist</option>
                        <option value="album_name">Album</option>
                        <option value="track_name">Track</option>
                    </select>

                <input type="submit" value="Search!" />
                </form>
            </p>
<?php
// set db variables
// Edit these with your own info

$dbhost = "xxxxxxxxx.xxxx.xxxx.co.uk";
$dbuser = "xxxxxx";
$dbpass = "xxxxxxxxxx";
$dbname = "xxxxxx";

/* If the form has been submitted with a supplied keyword */
if (isset($_POST['field'])){
include "pgsql.class.php";
/* Connect to server and select database */
$pgsqldb = new pgsql($dbhost,$dbuser,$dbpass,$dbname);
$pgsqldb->connect();

/* Set the posted variables to a convenient name */
$keyword = $_POST['keyword'];
$field = $_POST['field'];

/* Create the query based on the type of search */
if ($field == "artist_name") {
	$pgsqldb->query("SELECT artist_name, genre FROM artists WHERE artist_name='$keyword'");
}
else if($field == "album_name") {
	$pgsqldb->query("SELECT album_name FROM albums WHERE album_name='$keyword'");
}
else if($field == "track_name") {
	$pgsqldb->query("SELECT track_name FROM tracks WHERE track_name='$keyword'");
}

// if records are found, output them
if ($pgsqldb->numrows() > 0){
	while ($row = $pgsqldb->fetchobject()) {
		if ($field == "artist_name") {
			echo "Artist: $row->artist_name<br />Genre: $row->genre<br />";
		}
		else if($field == "album_name"){
			echo "Album: $row->album_name<br />";
		}
		else if($field == "track"){
			echo "Track: $row->track_name<br />";
		}
	}
}
else
{
echo "No Results found.";
}
}
?>
    </body>
</html>

 

<?php
class pgsql {
   private $linkid;      // PostgreSQL link identifier
   private $host;        // PostgreSQL server host
   private $user;        // PostgreSQL user
   private $passwd;      // PostgreSQL password
   private $db;          // PostgreSQL database
   private $result;      // Query result
   private $querycount;  // Total queries executed
   /* Class constructor. Initializes the $host, $user, $passwd
      and $db fields. */
   function __construct($host, $db, $user, $passwd) {
      $this->host = $host;
      $this->user = $user;
      $this->passwd = $passwd;
      $this->db = $db;
   }
   /* Connects to the PostgreSQL Database */
   function connect(){
      try{
         $this->linkid = @pg_connect("host=$this->host dbname=$this->db
            user=$this->user password=$this->passwd");
         if (! $this->linkid)
            throw new Exception("Could not connect to PostgreSQL server.");
      }
   catch (Exception $e) {
      die($e->getMessage());
   }
}
/* Execute database query. */
function query($query){
   try{
      $this->result = @pg_query($this->linkid,$query);
      if(! $this->result)
         throw new Exception("The database query failed.");
   }
   catch (Exception $e){
      echo $e->getMessage();
   }
   $this->querycount++;
   return $this->result;
}
/* Determine total rows affected by query. */
function affectedRows(){
   $count = @pg_affected_rows($this->linkid);
   return $count;
}
/* Determine total rows returned by query */
function numRows(){
   $count = @pg_num_rows($this->result);
   return $count;
}
/* Return query result row as an object. */
function fetchObject(){
   $row = @pg_fetch_object($this->result);
   return $row;
}
/* Return query result row as an indexed array. */
function fetchRow(){
   $row = @pg_fetch_row($this->result);
   return $row;
}
/* Return query result row as an associated array. */
function fetchArray(){
   $row = @pg_fetch_array($this->result);
   return $row;
}
   /* Return total number of queries executed during
      lifetime of this object. Not required, but
      interesting nonetheless. */
   function numQueries(){
      return $this->querycount;
   }
}
/* Return the number of fields in a result set */
function numberFields() {
   $count = @pg_num_fields($this->result);
   return $count;
}
/* Return a field name given an integer offset. */
function fieldName($offset){
   $field = @pg_field_name($this->result, $offset);
   return $field;
}
function getResultAsTable() {
   if ($this->numrows() > 0) {
      // Start the table
      $resultHTML = "<table border='1'>\n<tr>\n";
      // Output the table headers
      $fieldCount = $this->numberFields();
      for ($i=0; $i < $fieldCount; $i++){
          $rowName = $this->fieldName($i);
          $resultHTML .= "<th>$rowName</th>";
      } // end for
      // Close the row
      $resultHTML .= "</tr>\n";
      // Output the table data
      while ($row = $this->fetchRow()){
          $resultHTML .= "<tr>\n";
          for ($i = 0; $i < $fieldCount; $i++)
             $resultHTML .= "<td>".htmlentities($row[$i])."</td>";
          $resultHTML .= "</tr>\n";
      }
      // Close the table
      $resultHTML .= "</table>";
   }
   else {
      $resultHTML = "<p>No Results Found</p>";
   }
   return $resultHTML;
}

function pageLinks($totalpages, $currentpage, $pagesize, $parameter) {
   // Start at page one
   $page = 1;
   // Start at record 0
   $recordstart = 0;
   // Initialize page links
   $pageLinks = '';
   while ($page <= $totalpages) {
      // Link the page if it isn't the current one
      if ($page != $currentpage) {
         $pageLinks .= "<a href=\"".$_SERVER['PHP_SELF'].
         "?$parameter=$recordstart\">$page</a> ";
      // If the current page, just list the number
      }
      else {
         $pageLinks .= "$page ";
      }
      // Move to the next record delimiter
      $recordstart += $pagesize;
      $page++;
   }
   return $pageLinks;
}

?>

 

im recieving an error message from the second part of the code that reads....

 

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home2/webusers/07/344740/public_html/mediamart/pgsql.class.php on line 3

 

this is after i submit the search.

 

the databse was built with PuTTy onto an apache server. i may have some sill errors as im new to this. if anyone can tell me where my mistakes are id appreciate it. Thankyou

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.