Jump to content

Recommended Posts

Hello-Why doesn't this simple query work? Nothing prints. The variable, $item4, is a one-word text string submitted from a form. If I substitute an actual keyword in the query instead of the variable, it works.
Thank you.

<?
echo ("$item4"); //just testing to check the variable is correctly being sent from the form

$query = mysql_query("select make from table1 where keyword = '$item4' ");
$result = $query;
while ($row = mysql_fetch_array($result)){
print (" " . $row["make"] . " ");
}
?>
Link to comment
https://forums.phpfreaks.com/topic/3947-why-doent-this-simple-query-work/
Share on other sites

Try this to see if your query is actually returning anything, it might be that there are not any matches...
[code]<?php
$result = mysql_query("SELECT `make` FROM `table1` WHERE `keyword`='$item4'");
if(mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
        echo $row['make']."<br/>";
    }
} else {
    echo "There were no matches for the keyword you have supplied.";
}
?>[/code]
G'day

Not to sure on the whole fetch and while part, I do it differnetly, (i should convert cause all you guys seem to do it like that though)

Have you checked case in the query and for the arrays? a lot of probs I get are mainly due to not having the right letter case everything seems very case sensitive when using PHP and MySQL on an apache server (as opposed to using MS softwares which I think most of us start with).
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.