kpetsche20 Posted July 4, 2008 Share Posted July 4, 2008 Everytime I execute the code below even when a result is in the database it only displays it works. <? if(isset($_POST['Submit'])) { $searchsql = "SELECT * FROM tblpeople"; $searchquery = mysql_query($searchsql); while($data = mysql_fetch_array($searchquery)) { $search = $data['tblpeople'];} if($data['tblpeople'] != $_POST['search']) { echo "works"; } else { "doesn't work";} } ?> Link to comment https://forums.phpfreaks.com/topic/113258-problem-with-php-search-code/ Share on other sites More sharing options...
br0ken Posted July 4, 2008 Share Posted July 4, 2008 Try this... <?php if(isset($_POST['Submit'])) { $searchsql = "SELECT * FROM tblpeople"; $searchquery = mysql_query($searchsql); while($data = mysql_fetch_array($searchquery)) { $search = $data['tblpeople'];} if($data['tblpeople'] != $_POST['search']) { echo "works"; } else { "doesn't work";} } } ?> Link to comment https://forums.phpfreaks.com/topic/113258-problem-with-php-search-code/#findComment-581906 Share on other sites More sharing options...
kpetsche20 Posted July 4, 2008 Author Share Posted July 4, 2008 Doesn't work even when i typed in the correct info it gives me the same error as if it was incorrect.. Here's the new code <?php if(isset($_POST['Submit'])) { $searchsql = "SELECT * FROM tblpeople"; $searchquery = mysql_query($searchsql); while($data = mysql_fetch_array($searchquery)) { $search = $data['tblpeople'];} if($data['tblpeople'] != $_POST['search']) { echo "doesn't work"; } else { "works";} } ?> Link to comment https://forums.phpfreaks.com/topic/113258-problem-with-php-search-code/#findComment-581914 Share on other sites More sharing options...
br0ken Posted July 4, 2008 Share Posted July 4, 2008 What is the name of the field in the table that you're trying to extract data from? $search = $data['tblpeople'] - Where you have tblpeople (the table name) you need to have the field name you want to get the data from. Link to comment https://forums.phpfreaks.com/topic/113258-problem-with-php-search-code/#findComment-581968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.