Page 1 of 1

Unknown column 'charlie' in 'field list'

Posted: Wed Nov 11, 2009 7:18 am
by sheepysheep
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:

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>
PHP2.php:

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>";
        }
}
?>
connect.php:

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");
 
?>
PHP.php outputs:
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
Thank you in advance, sorry for ridiculously long post!!

Re: Unknown column 'charlie' in 'field list'

Posted: Wed Nov 11, 2009 7:24 am
by jackpf
Strings need quotes.

Re: Unknown column 'charlie' in 'field list'

Posted: Wed Nov 11, 2009 7:36 am
by sheepysheep
422 word question, 3 word answer.

That worked, thank you very much buddy!!!

if anyone cares:

Code: Select all

$query = "UPDATE folders SET name='{$new_name}' WHERE id='{$this->id}'";

Re: Unknown column 'charlie' in 'field list'

Posted: Wed Nov 11, 2009 7:48 am
by jackpf
:)