happygolucky Posted May 7, 2009 Share Posted May 7, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Change echo "<td>$row[‘Artist’]</td>"; echo "<td>$row[‘Genre’]</td>"; To echo '<td>' . $row['artist_name'] . '</td>'; echo '<td>' . $row['genre'] . '</td>'; Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828793 Share on other sites More sharing options...
happygolucky Posted May 7, 2009 Author Share Posted May 7, 2009 Thanks for the quick reply Ken. I ammended as suggested and uploaded to the server. However the problem still remains. Im stumped. Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828796 Share on other sites More sharing options...
Philip Posted May 7, 2009 Share Posted May 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828801 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Learn PHP dude. Change: $var = @$_POST["keyword"] ; To $keyword = $_POST['keyword']; Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828802 Share on other sites More sharing options...
happygolucky Posted May 7, 2009 Author Share Posted May 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828811 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828821 Share on other sites More sharing options...
happygolucky Posted May 7, 2009 Author Share Posted May 7, 2009 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828833 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Well, you would put the CENTER and TABLE tags outside of the loop and just leave the TR and TD tags inside like you have it now. Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828841 Share on other sites More sharing options...
revraz Posted May 7, 2009 Share Posted May 7, 2009 Don't forget to close your table. Quote Link to comment https://forums.phpfreaks.com/topic/157263-solved-database-is-returning-nothing/#findComment-828859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.