Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
mysql error 1146 adding suffix to table
Old 04-04-2011, 03:48 PM mysql error 1146 adding suffix to table
Whathadiv's Avatar
Super Talker

Posts: 99
Name: Justin Paul
Trades: 0
I'm getting this error when trying to access my table

PHP Code:
Error Number1146
Table 
'mytables' doesn't exist
SELECT * FROM (mytables) 
Assume my created table is called "mytable" and it's looking for "mytables"


I didn't ask to look for that table but if I change the name of the table manually to mytables then it works fine.


Can someone help me out? Why is it looking for the wrong name or adding a suffix when I don't have any queries looking for that table name?


Thanks
__________________

Please login or register to view this content. Registration is FREE
Whathadiv is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-04-2011, 04:10 PM Re: mysql error 1146 adding suffix to table
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
No idea, do we get to see more code?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-04-2011, 04:18 PM Re: mysql error 1146 adding suffix to table
Whathadiv's Avatar
Super Talker

Posts: 99
Name: Justin Paul
Trades: 0
I'm creating a fancybox module for a CodeIgniter CMS

PHP Code:
<?php defined('BASEPATH') or exit('No direct script access allowed');

class 
Module_Fancybox extends Module {

    public 
$version '1.0';

    public function 
install()
    {
        
$this->dbforge->drop_table('fancybox');

        
$fancybox "
            CREATE TABLE `fancybox` (
              `id` int(11) NOT NULL AUTO_INCREMENT,
              `title` varchar(255) NOT NULL,
              `second_title` varchar(255) NOT NULL,
              `slug` varchar(255) NOT NULL,
              `fancyid` varchar(255) NOT NULL,
              `content` text,
              `parent` int(11) DEFAULT NULL,
              `updated_on` int(15) NOT NULL,
              `preview` varchar(255) DEFAULT NULL,
              `enable_comments` int(1) DEFAULT NULL,
              `published` int(1) DEFAULT NULL,
              PRIMARY KEY (`id`),
              UNIQUE KEY `slug` (`slug`),
              UNIQUE KEY `fancyid` (`fancyid`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8
        "
;

        if(
$this->db->query($fancybox))
        {
            return 
TRUE;
        }
    }

    public function 
uninstall()
    {
        if(
$this->dbforge->drop_table('fancybox'))
        {
            return 
TRUE;
        }
    }


    public function 
upgrade($old_version)
    {
        
// Upgrade Logic
        
return TRUE;
    }
}
If there's any specific code I should provide, please let me know
__________________

Please login or register to view this content. Registration is FREE
Whathadiv is offline
Reply With Quote
View Public Profile
 
Old 04-04-2011, 04:45 PM Re: mysql error 1146 adding suffix to table
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
So ...

"mytable" equates to "fancybox"

but "mytables" equates to ?????
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-04-2011, 04:48 PM Re: mysql error 1146 adding suffix to table
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Oh and where does the SELECT * query get created?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-04-2011, 06:16 PM Re: mysql error 1146 adding suffix to table
Whathadiv's Avatar
Super Talker

Posts: 99
Name: Justin Paul
Trades: 0
No mytables equates to nothing because the it's called mytable without the 's' but when selecting it tries to select mytables, adding an 's' to the end of the name.

i.e: i want to select mytable

it's actually trying to select mytable(s)

My apologies if i'm not clear, SQL is still pretty new to me

This is my admin.php controller

PHP Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * The fancybox module enables users to create inline content inside of a fancybox.
 *
 * @author         Justin Hubbard - eLIONweb
 * @package     PyroCMS
 * @subpackage     Fancybox Module
 * @category     Modules
 * @license     Apache License v2.0
 */
class Admin extends Admin_Controller
{
    public 
$id 0;

    
/**
     * Validation rules for creating a new fancybox
     *
     * @var array
     * @access private
     */
    
private $fancybox_validation_rules = array(
        array(
            
'field' => 'title',
            
'label' => 'lang:fancybox.title_label',
            
'rules' => 'trim|max_length[255]|required'
        
),
        array(
            
'field' => 'second_title',
            
'label' => 'lang:fancybox.second_title_label',
            
'rules' => 'trim|max_length[255]'
        
),
        array(
            
'field' => 'slug',
            
'label' => 'lang:fancybox.slug_label',
            
'rules' => 'trim|max_length[255]|required|callback__check_slug'
        
),
        array(
            
'field' => 'fancyid',
            
'label' => 'lang:fancybox.fancyid_label',
            
'rules' => 'trim|required|callback__check_fancyid'
        
),
        array(
            
'field' => 'content',
            
'label' => 'lang:fancybox.content_label',
            
'rules' => 'trim'
        
),
        array(
            
'field' => 'enable_comments',
            
'label' => 'lang:fancybox.comments_label',
            
'rules' => 'trim'
        
),
        array(
            
'field' => 'published',
            
'label' => 'lang:fancybox.published_label',
            
'rules' => 'trim'
        
)

    );

    
/**
     * Constructor method
     *
     * @author Justin Hubbard - elIONweb
     * @access public
     * @return void
     */
    
public function __construct()
    {
        
parent::__construct();

        
// Load all the required classes
        
$this->load->model('fancybox_m');
        
$this->load->library('form_validation');
        
$this->lang->load('fancybox');
        
$this->load->helper('html');

        
$this->load->model('files/file_folders_m');

        
$this->template->set_partial('shortcuts''admin/partials/shortcuts');
    }

    
/**
     * List all existing fancybox
     *
     * @access public
     * @return void
     */
    
public function index()
    {
        
// Get all the fancybox
        
$fancybox $this->fancybox_m->get_all();

        
// Load the view
        
$this->template
            
->title($this->module_details['name'])
            ->
append_metadata(js('functions.js''fancybox'))
            ->
set('fancybox'$fancybox)
            ->
build('admin/index');
    }

    
/**
     * Create a new fancybox
     *
     * @access public
     * @return void
     */
    
public function create()
    {
        
$this->file_folders_m->folder_tree();
        
$file_folders $this->file_folders_m->get_folders();

        
// Set the validation rules
        
$this->form_validation->set_rules($this->fancybox_validation_rules);

        if (
$this->form_validation->run() )
        {
            if (
$this->fancybox_m->insert($_POST))
            {
                
// Everything went ok..
                
$this->session->set_flashdata('success'lang('fancybox.create_success'));
                
redirect('admin/fancybox');
            }
            
            
// Something went wrong..
            
else
            {
                
$this->session->set_flashdata('error'lang('fancybox.create_error'));
                
redirect('admin/fancybox/create');
            }
        }

        
// Required for validation
        
foreach ($this->fancybox_validation_rules as $rule)
        {
            
$fancybox->{$rule['field']} = $this->input->post($rule['field']);
        }

        
$this->template
            
->append_metadatajs('form.js''fancybox') )
            ->
append_metadata(js('functions.js''fancybox') )
            ->
append_metadatacss('fancy-style.css''fancybox') )
            ->
title($this->module_details['name'], lang('fancybox.new_fancybox_label'))
            ->
set('fancybox'$fancybox)
            ->
set('file_folders'$file_folders)
            ->
build('admin/new_fancybox');
    }

    
/**
     * Manage an existing fancybox
     *
     * @author Yorick Peterse - Justin Hubbard
     * @access public
     * @param int $id The ID of the fancybox to manage
     * @return void
     */
    
public function manage($id)
    {
        
$this->form_validation->set_rules($this->fancybox_validation_rules);

        
// Get the fancybox
        
$fancybox         $this->fancybox_m->get_all();
        
$fancybox         $this->fancybox_m->get($id);

        if ( empty(
$fancybox) )
        {
            
$this->session->set_flashdata('error'lang('fancybox.exists_error'));
            
redirect('admin/fancybox');
        }

        
$this->id $id;

        
// Valid form data?
        
if ($this->form_validation->run() )
        {
            
// Try to update the fancybox
            
if ($this->fancybox_m->update($id$_POST) === TRUE )
            {
                
$this->session->set_flashdata('success'lang('fancybox.update_success'));
                
redirect('admin/fancybox/manage/' $id);
            }
            else
            {
                
$this->session->set_flashdata('error'lang('fancybox.update_error'));
                
redirect('admin/fancybox/manage/' $id);
            }
        }

        
// Required for validation
        
foreach ($this->fancybox_validation_rules as $rule)
        {
            if (
$this->input->post($rule['field']))
            {
                
$fancybox->{$rule['field']} = $this->input->post($rule['field']);
            }
        }

        
$this->template
            
->title($this->module_details['name'], lang('fancybox.manage_fancybox_label'))
            ->
append_metadatacss('fancy-style.css''fancybox') )
               ->
append_metadatajs('drag_drop.js''fancybox') )
            ->
append_metadata(js('functions.js''fancybox') )
            ->
append_metadatajs('form.js''fancybox') )
            ->
set('fancybox'$fancybox)
            ->
set('fancybox'$fancybox)
            ->
build('admin/manage_fancybox');
    }

    
/**
     * Delete an existing fancybox
     *
     * @author Justin Hubbard - eLIONweb
     * @access public
     * @param int $id The ID of the fancybox to delete
     * @return void
     */
    
public function delete($id NULL)
    {
        
$id_array = array();

        
// Multiple IDs or just a single one?
        
if ($_POST )
        {
            
$id_array $_POST['action_to'];
        }
        else
        {
            if (
$id !== NULL )
            {
                
$id_array[0] = $id;
            }
        }

        if ( empty(
$id_array) )
        {
            
$this->session->set_flashdata('error'lang('fancybox.id_error'));
            
redirect('admin/fancybox');
        }

        
// Loop through each ID
        
foreach ( $id_array as $id)
        {
            
// Get the fancybox
            
$fancybox $this->fancybox_m->get($id);

            
// Does the fancybox exist?
            
if ( !empty($fancybox) )
            {

                
// Delete the fancybox along with all the content from the database
                
if ($this->fancybox_m->delete($id) )
                {
                    
$this->session->set_flashdata('error'sprintflang('fancybox.folder_error'), $fancybox->title));
                    
redirect('admin/fancybox');
                }
                else
                {
                    
$this->session->set_flashdata('error'sprintflang('fancybox.delete_error'), $fancybox->title));
                    
redirect('admin/fancybox');
                }
            }
        }

        
$this->session->set_flashdata('success'lang('fancybox.delete_success'));
        
redirect('admin/fancybox');
    }

    
/**
     * Callback method that checks the slug of the fancybox
     * @access public
     * @param string title The slug to check
     * @return bool
     */
    
public function _check_slug($slug '')
    {
        if ( ! 
$this->fancybox_m->check_slug($slug$this->id))
        {
            return 
TRUE;
        }

        
$this->form_validation->set_message('_check_slug'sprintf(lang('fancybox.already_exist_error'), $slug));

        return 
FALSE;
    }

    
/**
     * Callback method that checks the file folder of the fancybox
     * @access public
     * @param int id The id to check if file folder exists or prep to create new folder
     * @return bool
     */
    
public function _check_folder($id 0)
    {
        
// Is not creating or folder exist.. Nothing to do.
        
if ($this->method !== 'create')
        {
            return 
$id;
        }
        elseif (
$this->file_folders_m->exists($id))
        {
            if (
$this->fancybox_m->count_by('folder_id'$id) > 0)
            {
                
$this->form_validation->set_message('_check_folder'lang('fancybox.folder_duplicated_error'));

                return 
FALSE;
            }

            return 
$id;
        }

        
$folder_name $this->input->post('title');
        
$folder_slug url_title(strtolower($folder_name));

        
// Check if folder already exist, rename if necessary.
        
$i 0;
        
$counter '';
        while ( ((int) 
$this->file_folders_m->count_by('slug'$folder_slug $counter) > 0))
        {
            
$counter '-' . ++$i;
        }

        
// Return data to create a new folder to this fancybox.
        
return array(
            
'name' => $folder_name . ($i ' (' $i ')' ''),
            
'slug' => $folder_slug $counter
        
);
    }
}
Maybe you can help me cause I'm not sure exactly where it's SELECTing from, otherwise it's ok, no biggie
__________________

Please login or register to view this content. Registration is FREE
Whathadiv is offline
Reply With Quote
View Public Profile
 
Old 04-04-2011, 06:47 PM Re: mysql error 1146 adding suffix to table
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Seeing that code is all well and good, but as it doesn't mention "mytable" anywhere, I'm not entirely sure how we are going to find what is adding the extraneous 's'
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-04-2011, 07:52 PM Re: mysql error 1146 adding suffix to table
Whathadiv's Avatar
Super Talker

Posts: 99
Name: Justin Paul
Trades: 0
Well the table is actually called "fancybox"

it's trying to select fancyboxs

mytable was just an example
__________________

Please login or register to view this content. Registration is FREE
Whathadiv is offline
Reply With Quote
View Public Profile
 
Old 04-05-2011, 03:27 PM Re: mysql error 1146 adding suffix to table
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by Whathadiv View Post
Well the table is actually called "fancybox"

it's trying to select fancyboxs

mytable was just an example
So I was correct with this thought.
Quote:
Originally Posted by chrishirst View Post
So ...

"mytable" equates to "fancybox"

but "mytables" equates to ?????
All I can suggest is that the problem is in the code that creates the query (code which hasn't been posted)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-07-2011, 02:56 PM Re: mysql error 1146 adding suffix to table
Whathadiv's Avatar
Super Talker

Posts: 99
Name: Justin Paul
Trades: 0
Hey thanks Chris for all your help but I decided to go a different route considering I couldn't get that working and was in a time crunch.

Much appreciated!
__________________

Please login or register to view this content. Registration is FREE
Whathadiv is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql error 1146 adding suffix to table
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33765 seconds with 12 queries