PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Newbie!!
I need help with the quotes arround the field names in the WHERE conditions.
The variables are passed in a function and contain string info. I am unable to get this to execute. Any help?
// should it be this:
$query = "SELECT * FROM runners WHERE firstname=$firstname AND lastname=$lastname AND passw=$pw";
// or should it be this:
$query = "SELECT * FROM runners WHERE firstname='$firstname' AND lastname='$lastname' AND passw='$pw'";
// or this:
$query = 'SELECT * FROM runners WHERE 'firstname' = "' .$firstname. '" AND 'lastname' = "' .$lastname. '" AND 'passw' = "' .$pw.'";
These are names that come from a entry form. The entry form input line has a designated size of 50. When I DESCRIBE the file in the console, the type is designated as char(30) which I am assuming means 30 characters. Do I need to make sure everything matches in size?
The first one will not work. Second and third may.
A CHAR(30) means you can have up to 30 characters in that field. If you provide more they will be cut off - warnings (which are hard to get to in PHP) but no errors.
If you don't want them truncated them you should check that the data is short enough; if not you can print a message or whatever you want to do.
katkat wrote:I got the 2nd one to work. Thanks so much for that! But now I have another problem:
If a user enters a name that doesn't exist, what is the test?
I was using a:
if ($result) { then display the record } else display an error message.
But what is happening is the name that the user enters (even though it is not in the file) is displayed and no error message.
That's because returning an empty result set is not an error, even though it may not be what you wanted. There are several ways to handle this. Instead of testing $result, you can test