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.

PHP Forum


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



Freelance Jobs

Reply
Problem inserting into two tables.
Old 11-10-2008, 08:48 PM Problem inserting into two tables.
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Hiya

I cant seem to get my script to insert data into two different tables.
PHP Code:
function createpage($title$category$layout$comments) {
    
$sql_text "SELECT id, pages, username, page_limit FROM ".$this->TABLES['users']." WHERE username = '".$_COOKIE['user']."'";
    
$data $this->sql->Select($sql_text);
    
$i=0;
    if (
$data[$i]['pages'] == $data[$i]['page_limit']) {
                  
$this->throwException(1018);
    return 
false;
        } else {
        
$filename $_COOKIE['user'] . $data[$i]['pages'];
    
$this->sql->Insert("INSERT INTO ".$this->TABLES['pagecontent']." (title, layout, user, filename) VALUES ('".$title."', '".$layout."', '".$_COOKIE['user']."', '".$filename."'");

$this->sql->Insert("INSERT INTO ".$this->TABLES['pages']." (category, comments, user, filename, title, date_created) VALUES ('".$category."', '".$comments."', '".$_COOKIE['user']."', '".$filename."', '".$title."', NOW()+1)"); 
For some reason its inputting the data into ".$this->TABLES['pages']." but not ".$this->TABLES['pagecontent']."

I know its doubling data but it seems neater to me to have them seperated.
At this point in time I have it all being put into ".$this->TABLES['pages']." Just for future reference why wouldnt it put it into 2 tables?
I checked all naming and spelling on fields etc.
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-11-2008, 04:38 AM Re: Problem inserting into two tables.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
$sql "...";
echo 
$sql
to ensure that the query is formed correctly
check logs or anything to read sql warning if any
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-11-2008, 05:01 AM Re: Problem inserting into two tables.
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
No errors, inputs into the one table, but not the other.
Its very weird.

Unless somethings wrong in database.
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Old 11-11-2008, 10:36 AM Re: Problem inserting into two tables.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
If a record is not inserted the error definitely exists. Search.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-11-2008, 05:22 PM Re: Problem inserting into two tables.
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
If a record is not inserted the error definitely exists. Search.
So the code looks correct?
PHP Code:
function createpage($title$category$layout$comments) {
    
$sql_text "SELECT id, pages, username, page_limit FROM ".$this->TABLES['users']." WHERE username = '".$_COOKIE['user']."'";
    
$data $this->sql->Select($sql_text);
    
$i=0;
    if (
$data[$i]['pages'] == $data[$i]['page_limit']) {
                  
$this->throwException(1018);
    return 
false;
        } else {
        
$filename $_COOKIE['user'] . $data[$i]['pages'];
    
$this->sql->Insert("INSERT INTO ".$this->TABLES['pages']." (category, comments, user, filename, title, date_created) VALUES ('".$category."', '".$comments."', '".$_COOKIE['user']."', '".$filename."', '".$title."', NOW()+1)");

$this->sql->Insert("INSERT INTO ".$this->TABLES['pages']." (category, comments, user, filename, title, date_created) VALUES ('".$category."', '".$comments."', '".$_COOKIE['user']."', '".$filename."', '".$title."', NOW()+1)"); 
So that techniqually should put the entry in twice in the same table?
(will check later)
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Old 11-12-2008, 02:09 AM Re: Problem inserting into two tables.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
I know nothing about your table structure and about your input data. The query may be semantically correct but in fact it may refer to not existing fields, may have unescaped quotes and so on.

Learn to debug. Most mysql error messages are quite self explanatory. If you are unable to locate the error yourself nobody would be able to do it for you.

If a query does not do what you expect, FIRST OF ALL echo that query somewhere and insert it into the command line mysql client. This is the most simple and most quick way to find out what is wrong with your query.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-12-2008, 08:00 PM Re: Problem inserting into two tables.
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Thanks,
Just trying to narrow it down abit to see if the php code was actually sound.
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem inserting into two tables.
 

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.29130 seconds with 12 queries