Re: Query Returning Error
| From: | Chris Dowell | Date: | Wed, 13 Oct 2004 10:56:37 +0000 |
| Subject: | Re: Query Returning Error | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199353@lists.php.net to get a copy of this message | ||
You can get around this problem more easily by putting your variables inside curly brackets when they appear inside strings.
See here: http://uk.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
Or as an example:
<?php
$Query01 = "SELECT * FROM Users
WHERE UserID = '{$_POST['TXT_UserID']}'
AND UserPassword = '{$_POST['TXT_UserPassword']}'";
$Result01 = mysql_query($Query01) or die ("Error 01: " . mysql_error());
?>
Note also that you didn't quote the index you were using inside the $_POST array. This is wrong - it will work in "raw" PHP because it will be interpreted as an undefined constant, and thus replaced with the string, however the behaviour inside a quoted string is even less correct, and will almost certainly not do what you expect.
Hope this helps
Cheers
Chris
Graham Cossey wrote:
Besides adding $ to Query01, I have had little luck in the past when using $_POST or $_GET directly in an evaluated string. If you are still having problems, try something like: <?php $user = $_POST['TXT_UserID']; $pwd = $_POST['TXT_UserPassword']; // Authenticate User: $Query01 = "SELECT * FROM UsersWHERE UserID='$user' AND UserPassword='$pwd'";$Result01 = mysql_query($Query01) or die("Error 01: " . mysql_error()); ?> HTH Graham-----Original Message----- From: Harlequin [mailto:michael.mason@arraspeople.co.uk] Sent: 13 October 2004 08:32 To: php-general@lists.php.net Subject: [PHP] Query Returning Error Morning all. this is such a basic question I'm embarrassed to ask but the query worked fine a few minutes ago and now returns an error: I get an error: Parse error: parse error, unexpected '=' in sample.php on line 2 [CODE] // Authenticate User: Query01 = "SELECT * FROM Users WHERE UserID='$_POST[TXT_UserID]' AND UserPassword='$_POST[TXT_UserPassword]'"; $Result01 = mysql_query($Query01) or die("Error 01: " . mysql_error()); [/CODE] WTF...? -- ----------------------------- Michael Mason Arras People www.arraspeople.co.uk ----------------------------- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php