tobimichigan Posted March 25, 2010 Share Posted March 25, 2010 Code Gurus I am amiss at what I could be missing here. I am trying to insert a current user with a valid session into the database along side other variables but sql keeps returning: "Error: Unknown column 'admin01' in 'field list' SQL: Insert into receipts(adno,adue,apaid,adebt,datereg,username) values('RC2345644','300','300','',SYSDATE(),admin01)". The admin01 is actually the current user I don't just know why its returning this specific error. All I want it to do is insert the current user with the other variables so I can keep track of the logged entries of the receipts. Any excellent pointer would be appreciated. Here's the code: <?php $adno=addslashes($_POST['adno']); $adue=addslashes($_POST['adue']); $apaid =addslashes($_POST['apaid']); $apaid=$adue-$apaid=addslashes($_POST['adebt']); $datereg=addslashes($_POST['datereg']); $username=addslashes($_POST['username']); $sql= "Insert into receipts(adno,adue,apaid,adebt,datereg,username) values('$adno','$adue','$apaid','$adebt',SYSDATE(),$_SESSION[username])"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } else header ("Location:Receipt_Success.php")?> Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/ Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 Put quotes around $_SESSION[username] in the query (this will fix this error, but you will immediately run into another ) Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/#findComment-1031738 Share on other sites More sharing options...
KevinM1 Posted March 25, 2010 Share Posted March 25, 2010 As an aside, you shouldn't use addslashes to escape your data. Use mysql_real_escape_string instead. Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/#findComment-1031746 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 And this line $apaid=$adue-$apaid=addslashes($_POST['adebt']); doesn't have much sense, does it? Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/#findComment-1031753 Share on other sites More sharing options...
tobimichigan Posted March 25, 2010 Author Share Posted March 25, 2010 Mich, funny though, I did not run into any other error. Its now working just fine. Thanks a mil...just one more thing Suppose I wanted to generate an input from an input..for example get the value of $adebt from $adue and $apaid such that $adebt=$adue-$apaid; and $adebt will be inserted along the other vairables.. how do I do that? <?php //session_start(); include("cn.php"); $adue=$_GET['adue']; $adebt=$_GET['adebt']; $apaid=$_GET['apaid']; $apaid=($adue)-($apaid); //$username=$_GET['[$_SESSION[username]']; $adno= mysql_real_escape_string($_POST['adno']); $adue= mysql_real_escape_string($_POST['adue']); $apaid = mysql_real_escape_string($_POST['apaid']); $apaid=$adue-$apaid= mysql_real_escape_string($_POST['adebt']); $datereg= mysql_real_escape_string($_POST['datereg']); $username= mysql_real_escape_string($_POST['username']); $sql= "Insert into receipts(adno,adue,apaid,adebt,datereg,username) values('$adno','$adue','$apaid','$adebt',SYSDATE(),'$_SESSION[username]')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } else header ("Location:Receipt_Success.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/#findComment-1031757 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 Mich, funny though, I did not run into any other error. Its now working just fine. A narrow escape, because you used $_SESSION[username] instead of $_SESSION['username']. If you used the second option (like you should actually), you would then need to put antire array into {} braces, like this: $sql= "Insert into receipts(adno,adue,apaid,adebt,datereg,username) values('$adno','$adue','$apaid','$adebt',SYSDATE(),'{$_SESSION['username']}')"; Suppose I wanted to generate an input from an input..for example get the value of $adebt from $adue and $apaid such that $adebt=$adue-$apaid; and $adebt will be inserted along the other vairables.. how do I do that? ... just like you did in this snippet? Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/#findComment-1031773 Share on other sites More sharing options...
tobimichigan Posted March 25, 2010 Author Share Posted March 25, 2010 "... just like you did in this snippet?" Do You mean <?php $adebt='adue-apaid'=mysql_real_escape_string($_POST['adebt']); ?> ? Would be the solution? Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/#findComment-1031837 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 Suppose I wanted to generate an input from an input..for example get the value of $adebt from $adue and $apaid such that $adebt=$adue-$apaid; $adebt=$adue-$apaid; Quote Link to comment https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/#findComment-1031861 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.