Problem inserting into two tables.
11-10-2008, 08:48 PM
|
Problem inserting into two tables.
|
Posts: 303
|
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
|
|
|
|
11-11-2008, 04:38 AM
|
Re: Problem inserting into two tables.
|
Posts: 1,226
Name: Mike
Location: Mataro, Spain
|
PHP Code:
$sql = "..."; echo $sql;
to ensure that the query is formed correctly
check logs or anything to read sql warning if any
|
|
|
|
11-11-2008, 05:01 AM
|
Re: Problem inserting into two tables.
|
Posts: 303
|
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
|
|
|
|
11-11-2008, 10:36 AM
|
Re: Problem inserting into two tables.
|
Posts: 1,226
Name: Mike
Location: Mataro, Spain
|
If a record is not inserted the error definitely exists. Search.
|
|
|
|
11-11-2008, 05:22 PM
|
Re: Problem inserting into two tables.
|
Posts: 303
|
Quote:
Originally Posted by mtishetsky
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
|
|
|
|
11-12-2008, 02:09 AM
|
Re: Problem inserting into two tables.
|
Posts: 1,226
Name: Mike
Location: Mataro, Spain
|
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.
|
|
|
|
11-12-2008, 08:00 PM
|
Re: Problem inserting into two tables.
|
Posts: 303
|
Thanks,
Just trying to narrow it down abit to see if the php code was actually sound.
__________________
Websites Created;
warscope.com
ratepayers.org.nz
|
|
|
|
|
« Reply to Problem inserting into two tables.
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|