Jump to content

Recommended Posts

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")?>

Link to comment
https://forums.phpfreaks.com/topic/196513-unknown-column-mystery/
Share on other sites

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");
?>


 

 

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?

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.