Jump to content

Recommended Posts

I've had several attempts at this and this is the script Im deciding to stick with. Its a search page to return a band name and the genre of the band into a table. On the page it returns nothing. Even though the data is in the database. Im even typing it exactly how it appears in the database. I have no idea where the error is. i knowim connected to the DB as ive told it to echo connected when there is a connection.

 

anyone know where my problem is

 

<html>
    <head><title>Media Mart</title>
    </head>
        <body>
            <center><img src="welcome.jpg" alt="welcome" /></center>
            
            <p>
                <center>
                    <form action="search.php" method="post">Search For...
                        <input type="text" name="keyword" size="60" maxlength="60" value="" />
                        <input type="submit" value="Search!" />
                    </form>
                </center>
            </p>
<?php

error_reporting (0);
$conn = @pg_connect("host=xxxxxxxxxxxxxxx user=xxxxxxxx password=xxxxxxxx dbname=xxxxxx"); 

if ($conn)  {

echo "connected to DB";

$var = @$_POST["keyword"] ;
    {
	$resultset =  "SELECT artist_name, genre FROM artists WHERE artist_name='$keyword";
        $artists = pg_query ($conn, $resultset);
        $array = pg_fetch_all($artists);
        
        foreach($array as $row);
{   
echo "<tr>";	
    echo "<td>$row[‘Artist’]</td>";	
    echo "<td>$row[‘Genre’]</td>";
    echo "</tr>";
}
    }
    }
    else
    {
    echo "no connection";
    } 

?>

Link to comment
https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/
Share on other sites

You're missing a ' in your query:

$resultset =  "SELECT artist_name, genre FROM artists WHERE artist_name='$keyword";

so, it should look like:

$resultset =  "SELECT artist_name, genre FROM artists WHERE artist_name='$keyword'";

 

Really I would have it changed to:

$resultset =  "SELECT artist_name, genre FROM artists WHERE artist_name='".$keyword."'";

 

Also, running

echo pg_last_error($conn);

would show your syntax error.

 

thanks its finally returning results now.

Thanks to both of you. I applied both the changes.

One thing i would like to say tho is the results arent in a table. with the headers above like set. any reason for this?

But again thankyou.

 

Since i am now having a seperate problem do i click this as solved and start a new thread?7

 

PS

i search Blue October and blue october is returned. is there a way to make it so it will return blue october even i just type blue? or make it not case sensative?  Thanks

1. You don't have a table tag.

2. Up to you. You can solve this and open a new topic. No one cares unless you're duplicating topics.

3. SQL is case-insensitive, so you don't need to make it case-insensitive. As for returning "blue october" typing "blue" use the SQL LIKE keyword. Click my *VERY* Helpful Link in my sig if you don't know what SQL LIKE is or how it works.

thanks. i had to laugh at what your very helpful link was. im using psql rather than sql. is there a difference? because Blue October is returning Blue October, whereas blue october is returning nothing. Perhaps that will be solved with the like statement. Im new to php, i only knew the very basics and bitten of more than i can chew. i could create a table in HTML with my eyes closed. Looking back over my code i realised i have no table headers. how would i fit these in with PHP? Sorry for being a pian.

{   echo '<center>';
    echo '<table>';
    echo '<tr>';	
    echo '<td>' . $row['artist_name'] . '</td>'; 
    echo '<td>' . $row['genre'] . '</td>';
    echo '</tr>';
    echo '</center>';
}

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.