BrentonHale Posted December 10, 2009 Share Posted December 10, 2009 It's not displaying or pulling anything out of the database. <html> <head> <title>Hale's Music World: Inventory Search Results</title> </head> <body> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="56%" id="table1" height="129"> <tr> <td bgcolor="#008000" colspan"3"> </td> </tr> <tr> <td colspan="3"> <p align="center"><font size="5" color="#0000FF"><b>Inventory Search Results</font></td></tr> <tr> <td bgcolor="#008000" colspan="3"> </td> </tr> <tr> <td width="33" align="center"> <font size="4" color="#008000"> <u>Artist</u></font></td> <td width="33%" align="center"> <font size="4" color="#008000"> <u>Title</u></font></td> <td width="33%" align="center"> <font size="4" color="#008000"> <u>Genre</u></font></td> </tr> <?php $link = mysql_connect('localhost','halesuser','hales123db'); mysql_select_db("halesmusicworld", $link); if ( isset( $_POST['Artist_Search'] ) AND $_POST['Artist_Search'] == 1 ) { echo '1'; $artist_search = mysql_real_escape_string( $_POST["Artist_Search"] ) . '1' ; $query = "select * from inventory where artist like '%" . $artist_search . "%'"; $result = mysql_query( "SELECT * FROM inventory", $link ); $num_rows = mysql_num_rows( $result ); echo 'Number of matching records=' . $num_rows . '<hr>'; } if ( isset( $_POST['Title_Search'] ) AND $_POST['Title_Search'] == 2 ) { echo '2'; $title_search = mysql_real_espace_string( $_POST["Title_Search"] ) . '2' ; $query = "select * from inventory where title like '%" . $title_search . "%'"; $result = mysql_query( "SELECT * FROM inventory", $link ); $num_rows = mysql_num_rows( $result ); echo 'Number of matching records='. $num_rows . '<hr>'; } if ( isset( $_POST['Genre_Search'] ) AND $_POST['Genre_Search'] == 3 ) { echo '3'; $genre_search=$_POST ['Genre'] ; $query= "select * from inventory where genre like '%".$genre_search."%'"; $query_results=mysql_query($query); $match_results=mysql_num_rows($query_results); echo 'Number of matching records='.$match_results. '<hr>'; } echo '</tr>'; for ($i=0; $i < $match_results; $i++) { echo '<tr>'; $row=mysql_fetch_array($query_results); echo '<td align="center">', ($row ['artist'] ), '</td>'; echo '<td align="center">', ($row ['title'] ), '</td>'; echo '<td align="center">', ($row ['genre'] ), '</td> </tr>'; } ?> <tr> <td bgcolor="#008000" colspan="3"> </td> </tr> </table> <p align="center"><i> <a href="HalesMusicWorld_Home.html"> <font face="Arial" size="5"> Return to </font></a><font face="Arial" size="5"> <a href="HalesMusicWorld_Home.html">HalesMusicWorld Home</font></i></p> </body> </html> It gives me the following error message: Notice: Undefined variable: match_results in C:\wamp\www\inventory_search.php on line 61 I believe it has something to do with this line of code : for ($i=0; $i < $match_results; $i++) Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/ Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2009 Share Posted December 10, 2009 your code should be something like, instead of the for loop while ($row=mysql_fetch_array($query_results) { echo '<tr>'; echo '<td align="center">', ($row ['artist'] ), '</td>'; echo '<td align="center">', ($row ['title'] ), '</td>'; echo '<td align="center">', ($row ['genre'] ), '</td> </tr>'; } Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974509 Share on other sites More sharing options...
BrentonHale Posted December 10, 2009 Author Share Posted December 10, 2009 your code should be something like, instead of the for loop while ($row=mysql_fetch_array($query_results) { echo '<tr>'; echo '<td align="center">', ($row ['artist'] ), '</td>'; echo '<td align="center">', ($row ['title'] ), '</td>'; echo '<td align="center">', ($row ['genre'] ), '</td> </tr>'; } I'm still not having any luck and it giving me the following error message now: Parse error: parse error in C:\wamp\www\inventory_search.php on line 61 Here is the code im using <html> <head> <title>Hale's Music World: Inventory Search Results</title> </head> <body> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="56%" id="table1" height="129"> <tr> <td bgcolor="#008000" colspan"3"> </td> </tr> <tr> <td colspan="3"> <p align="center"><font size="5" color="#0000FF"><b>Inventory Search Results</font></td></tr> <tr> <td bgcolor="#008000" colspan="3"> </td> </tr> <tr> <td width="33" align="center"> <font size="4" color="#008000"> <u>Artist</u></font></td> <td width="33%" align="center"> <font size="4" color="#008000"> <u>Title</u></font></td> <td width="33%" align="center"> <font size="4" color="#008000"> <u>Genre</u></font></td> </tr> <?php $link = mysql_connect('localhost','halesuser','hales123db'); mysql_select_db("halesmusicworld", $link); if ( isset( $_POST['Artist_Search'] ) AND $_POST['Artist_Search'] == 1 ) { echo '1'; $artist_search = mysql_real_escape_string( $_POST["Artist_Search"] ) . '1' ; $query = "select * from inventory where artist like '%" . $artist_search . "%'"; $result = mysql_query( "SELECT * FROM inventory", $link ); $num_rows = mysql_num_rows( $result ); echo 'Number of matching records=' . $num_rows . '<hr>'; } if ( isset( $_POST['Title_Search'] ) AND $_POST['Title_Search'] == 2 ) { echo '2'; $title_search = mysql_real_espace_string( $_POST["Title_Search"] ) . '2' ; $query = "select * from inventory where title like '%" . $title_search . "%'"; $result = mysql_query( "SELECT * FROM inventory", $link ); $num_rows = mysql_num_rows( $result ); echo 'Number of matching records='. $num_rows . '<hr>'; } if ( isset( $_POST['Genre_Search'] ) AND $_POST['Genre_Search'] == 3 ) { echo '3'; $genre_search=$_POST ['Genre'] ; $query= "select * from inventory where genre like '%".$genre_search."%'"; $query_results=mysql_query($query); $match_results=mysql_num_rows($query_results); echo 'Number of matching records='.$match_results. '<hr>'; } echo '</tr>'; while ($row=mysql_fetch_array($query_results) { echo '<tr>'; echo '<td align="center">', ($row ['artist'] ), '</td>'; echo '<td align="center">', ($row ['title'] ), '</td>'; echo '<td align="center">', ($row ['genre'] ), '</td> </tr>'; } ? > <tr> <td bgcolor="#008000" colspan="3"> </td> </tr> </table> <p align="center"><i> <a href="HalesMusicWorld_Home.html"> <font face="Arial" size="5"> Return to </font></a><font face="Arial" size="5"> <a href="HalesMusicWorld_Home.html">HalesMusicWorld Home</font></i></p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974518 Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2009 Share Posted December 10, 2009 sorry should have been while ($row=mysql_fetch_array($query_results)) { echo '<tr>'; echo '<td align="center">', ($row ['artist'] ), '</td>'; echo '<td align="center">', ($row ['title'] ), '</td>'; echo '<td align="center">', ($row ['genre'] ), '</td> </tr>'; } Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974520 Share on other sites More sharing options...
BrentonHale Posted December 10, 2009 Author Share Posted December 10, 2009 sorry should have been while ($row=mysql_fetch_array($query_results)) { echo '<tr>'; echo '<td align="center">', ($row ['artist'] ), '</td>'; echo '<td align="center">', ($row ['title'] ), '</td>'; echo '<td align="center">', ($row ['genre'] ), '</td> </tr>'; } now i'm getting Notice: Undefined variable: query_results in C:\wamp\www\inventory_search.php on line 60 Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\inventory_search.php on line 60 Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974526 Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2009 Share Posted December 10, 2009 you have to change that variable to the correct variable the result resource for the correct query Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974528 Share on other sites More sharing options...
BrentonHale Posted December 10, 2009 Author Share Posted December 10, 2009 you have to change that variable to the correct variable the result resource for the correct query I'm now error free in my code, i'm connected to mysql, but nothing is displaying from the database? <html> <head> <title>Hales Music World: Inventory Search Results</title> </head> <body> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="56%" id="table1" height="129"> <tr> <td bgcolor="#008000" colspan"3"> </td> </tr> <tr> <td colspan="3"> <p align="center"><font size="5" color="#0000FF"><b>Inventory Search Results</font></td></tr> <tr> <td bgcolor="#008000" colspan="3"> </td> </tr> <tr> <td width="33" align="center"> <font size="4" color="#008000"> <u>Artist</u></font></td> <td width="33%" align="center"> <font size="4" color="#008000"> <u>Title</u></font></td> <td width="33%" align="center"> <font size="4" color="#008000"> <u>Genre</u></font></td> </tr> <?php $link = mysql_connect('localhost','halesuser','hales123db'); if ( isset( $_POST['Artist_Search'] ) AND $_POST['Artist_Search'] == 1 ) { echo '1'; $artist_search = mysql_real_escape_string( $_POST["Artist_Search"] ) . '1' ; $query = "select * from inventory where artist like '%" . $artist_search . "%'"; $result = mysql_query( "SELECT * FROM inventory", $link ); $num_rows = mysql_num_rows( $result ); echo 'Number of matching records=' . $num_rows . '<hr>'; } if ( isset( $_POST['Title_Search'] ) AND $_POST['Title_Search'] == 2 ) { echo '2'; $title_search = mysql_real_espace_string( $_POST["Title_Search"] ) . '2' ; $query = "select * from inventory where title like '%" . $title_search . "%'"; $result = mysql_query( "SELECT * FROM inventory", $link ); $num_rows = mysql_num_rows( $result ); echo 'Number of matching records='. $num_rows . '<hr>'; } if ( isset( $_POST['Genre_Search'] ) AND $_POST['Genre_Search'] == 3 ) { echo '3'; $genre_search=$_POST ['Genre'] ; $query= "select * from inventory where genre like '%".$genre_search."%'"; $query_results=mysql_query($query); $match_results=mysql_num_rows($query_results); echo 'Number of matching records='.$match_results. '<hr>'; include 'inventory_search.html'; echo $query = "SELECT * FROM halesmusicworld;"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) '<tr>'; echo "Artist :{$row['artist']} </td>" . "Title : {$row['title']} </td>" . "Genre : {$row['genre']} </td></tr>"; } ?> <tr> <td bgcolor="#008000" colspan="3"> </td> </tr> </table> <p align="center"><i> <a href="HalesMusicWorld_Home.html"> <font face="Arial" size="5"> Return to </font></a><font face="Arial" size="5"> <a href="HalesMusicWorld_Home.html">HalesMusicWorld Home</font></i></p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974565 Share on other sites More sharing options...
SchweppesAle Posted December 10, 2009 Share Posted December 10, 2009 try this $row=mysql_fetch_array($query_results); echo var_dump($row); Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974593 Share on other sites More sharing options...
BrentonHale Posted December 10, 2009 Author Share Posted December 10, 2009 try this $row=mysql_fetch_array($query_results); echo var_dump($row); Still nothing is displaying: Link to comment https://forums.phpfreaks.com/topic/184598-help-with-php/#findComment-974598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.