MYSQL Error - INSERT, unknown column in field list

I keep getting the following error from this simple mysql statement, and I can't figure out why. I'm sure this is something obvious.

require_once("connect.php");

$query = mysql_query("SELECT * FROM accounts ORDER BY id DESC LIMIT 1");
$row = mysql_fetch_assoc($query);

$balanceold = $row['balance'];
$difference = $_POST['predec'].".".$_POST['dec'];

$category = $_POST['category'];
$notes = $_POST['notes'];

if(isset($_POST['in'])){
$balancenew = $balanceold + $difference;
$query = mysql_query("INSERT INTO accounts(currentbalance, balancein, category, notes) VALUES (".$balancenew.", ".$difference.", ".$category.", ".$notes.")");  
if($query){
header("Location: budget.php"); 
}
else{
die(mysql_error());
}
}

gives an error: Unknown column "payday" in the "list of fields"

here is my form code:

<form action=process.php method=post>

&pound;
<input type=text name=predec size=7>
. 
<input type=text name=dec size=4 value=00>
<br />
<select name=category>
<option value=payday>Payday</option>
</select>
<input type=text name=notes size=20>
<input type=submit name=in value=Deposit>
<input type=submit name=out value=Withdraw>
</form> 

The “database invoice table” contains the following fields:

id, int primary A_I

balancein decimal 10.2

balance decimal 10.2

current balance, decimal 10.2

varchar 50

notes varchar 255

date, timestamp

... in that order

+5
source share
4 answers

try this (enclose each variable inside a single quota query):

mysql_query("INSERT INTO accounts(currentbalance, balancein, category, notes) 
          VALUES ('$balancenew', '$difference', '$category', '$notes')");  

mysqli PDO SQL- mysql_real_escape_string():

$balancenew = mysql_real_escape_string($balancenew);

.

+13

, INSERT. String Date , sql. . . , ,

$query = mysql_query("INSERT INTO accounts(currentbalance, balancein, category, notes) 
                      VALUES ($balancenew, $difference, '$category', '$notes')");  
+1

, sql , , . , , db. .

0

, $notes $category. ', .

0
source

All Articles