2

The query in the following returns the data I want when I provide value I want to find a match for, however, I seem to be having difficulty when returning the data using the echo statements at the end:

$conn = mysqli_connect($host,$username,$password, $database) or die (mysql_error ());

$searched=$_POST['searched'];
$sound = soundex($searched);

$sql = "SELECT * FROM word_list WHERE sound = '$sound';";
$result = mysql_query($conn,$sql);
while($row = mysql_fetch_array($result)) {
echo $row['word'] . ':' . $row['sound'] . '<br />';
}
mysqli_close($conn);

?>

The output in a browser is a blank page (no errors logged, etc.). When I var_dump the input, I get the correct soundex value; I am not sure where I've overlooked something, as seen above, tried a few things I saw in another thread.

'string(4) "A000"' is the result of the var_dump. As I explained, when I use 'A000' in place of my $sound variable, the query is successful in MySQL, and returns a list of words with matching soundex values (stored in a column called 'sound'), but I can't seem to get it to readout as such in the browser.

3
  • 1
    coooool! in the first line you use "mysqli_connect", in 7 "mysql_query" :) Commented Jun 1, 2013 at 22:14
  • 1
    it might be because you have a mysqli connection but are using mysql_query? try changing to mysqli for all your code. Commented Jun 1, 2013 at 22:15
  • Blargh, thank you. That was it. Commented Jun 1, 2013 at 22:17

1 Answer 1

1

Try using mysqli_query instead of mysql_query. I think mysqli_connect returns an object and mysql_query needs a string.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I completely overlooked that.
No problem :) It's always easier to see someone else's mistakes ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.