jello32 Posted April 11, 2008 Share Posted April 11, 2008 I have two fields in a form. One field is populated by entries in my database. If the user wants to add a new payee they type the new payee in the new payee input box. I have the following sql: //check for new payee if(!empty($_POST['alternative_payeeID'])) { $sqlA = "INSERT INTO 'payees' (payeeID, pay_name) VALUES ('', '".$_POST['alternative_payeeID']."'); $resultA = @mysql_query($sqlA,$connection)or die(mysql_error()); $sqlB = "SELECT 'payeeID' FROM 'payees' WHERE 'pay_name' = '" + $_POST['alternative_payeeID'] + "'"; $payeeID = @mysql_query($sqlB,$connection)or die(mysql_error()); } else if(!empty($_POST['payeeID'])) { $payeeID = $_POST['payeeID']; } //build and issue query $sql = "INSERT INTO $table_name (transID, entityID, type, catID, cat_subID, methodID, accountID, payeeID, trans_date, amount, trans_desc) VALUES ('', '".$_POST['entityID']."', '".$_POST['style']."', '".$_POST['size']."','".$_POST['color']."','".$_POST['methodID']."', '".$_POST['accountID']."', '".$payeeID."', '{$_POST['txn_y']}-{$_POST['txn_m']}-{$_POST['txn_d']})', '".$_POST['amount']."', '".$_POST['description']."')"; $result = @mysql_query($sql,$connection)or die(mysql_error()); I'm getting a parse error on the line that says: $sqlB = "SELECT 'payeeID' FROM 'payees' WHERE 'pay_name' = '" + $_POST['alternative_payeeID'] + "'"; I've tried the following to no avail: $sqlB = "SELECT payeeID, pay_name FROM payees WHERE pay_name = '".$_POST['alternative_payeeID']."'; $sqlB = "SELECT `payeeID` FROM `payees` WHERE `pay_name` = '{$_POST['alternative_payeeID']}'", mysql_real_escape_string({$_POST['alternative_payeeID']}); $sqlB = "SELECT `payeeID` FROM `payees` WHERE `pay_name` = '{$_POST['alternative_payeeID']}'", mysql_real_escape_string($_POST['alternative_payeeID']); $sqlB = "SELECT `payeeID` FROM `payees` WHERE `pay_name` = '{$_POST['alternative_payeeID']}'"; $sqlB = "SELECT payeeID FROM `payees` WHERE `pay_name` = '$_POST['alternative_payeeID']'"; $sqlB = "SELECT 'payeeID' FROM 'payees' WHERE 'pay_name' = '" + $_POST['alternative_payeeID'] + "'"; None of which worked. Any ideas? Link to comment https://forums.phpfreaks.com/topic/100580-comparing-a-post-variable-in-a-select-statement/ Share on other sites More sharing options...
awpti Posted April 11, 2008 Share Posted April 11, 2008 $sqlB = "SELECT `payeeID` FROM `payees` WHERE `pay_name` = '{$_POST['alternative_payeeID']}'"; Notice the back-ticks. That should work fine. Link to comment https://forums.phpfreaks.com/topic/100580-comparing-a-post-variable-in-a-select-statement/#findComment-514418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.