Unknown column 'charlie' in 'field list'
Posted: Wed Nov 11, 2009 7:18 am
Hello. I am experimenting with classes at the moment. I have a database that contains menu items which I want to display down the left of a page. For now I am just echoing out information - all has been going well. I have just tried to update the database though and get the following error, but I can't work out what I'm doing wrong.
Can anyone offer me any advice??
PHP.php:
PHP2.php:
connect.php:
PHP.php outputs:
Can anyone offer me any advice??
PHP.php:
Code: Select all
<?php include('php2.php'); ?>
<html>
<head>
<title>
PHP Classes
</title>
</head>
<body>
<?php
echo "Hello!";
include("includes/connect.php");
$query = "SELECT * FROM folders";
$results = mysql_query($query);
while($line = mysql_fetch_array($results)) {
echo "<br/><br/><br/>";
$fold = 'fold_' . $line['name'];
$fold = new folderItem($line['id'], $line['name'], $line['lft'], $line['rgt'], $line['account_id'], $line['root']);
$fold->get_info();
$fold->make_link();
}
echo "<br/><br/>";
include("includes/connect.php");
$fold->set_name("charlie");
?>
</body>
</html>Code: Select all
<?php
class folderItem{
var $id;
var $name;
var $lft;
var $rgt;
var $account_id;
var $root;
function __construct($id, $name, $lft, $rgt, $account_id, $root){
$this->id = $id;
$this->name = $name;
$this->lft = $lft;
$this->rgt = $rgt;
$this->account_id = $account_id;
$this->root = $root;
}
function set_name($new_name){
$this->name = $new_name;
$query = "UPDATE folders SET name={$new_name} WHERE id={$this->id}";
$result = mysql_query($query);
if(!$result){
echo mysql_error() . "<br/>";
echo $query . "<br/>";
echo "Error in mysql<br/>";
}
}
function get_info(){
echo $this->id . "<br/>" . $this->name . "<br/>" . $this->lft . "<br/>"
. $this->rgt . "<br/>" . $this->account_id . "<br/>" . $this->root . "<br/>";
}
function make_link(){
echo "<a href='http://localhost/stable/index.php?folder='" . $this->id . ">" . $this->name . "</a>";
}
}
?>Code: Select all
<?php
$conn_server = "localhost";
$conn_user = "????";
$conn_pword = "????";
$con = mysql_connect($conn_server, $conn_user, $conn_pword);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
//
}
mysql_select_db("filebase");
?>Thank you in advance, sorry for ridiculously long post!!Hello!
126
Root
1
4
1
1
Root
193
Dillan
2
3
1
0
Dillan
190
Root
1
2
2
1
Root
Unknown column 'charlie' in 'field list'
UPDATE folders SET name=charlie WHERE id=190
Error in mysql