Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 11809
Latest: Rheingauner
New This Month: 1
New This Week: 0
New Today: 0
Stats
Total Posts: 41640
Total Topics: 7280
Most Online Today: 92
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 1
Guests: 41
Total: 42

Author Topic: Importing TP Portal Files Error  (Read 4268 times)

0 Members and 1 Guest are viewing this topic.

Offline Pegasys

  • Member
  • *
  • Posts: 10
    • View Profile
Importing TP Portal Files Error
« on: February 21, 2010, 11:41:41 pm »
I am getting the following error when trying to import download file from TP Portal:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3
File: /home/jphayden/public_html/forum2/Sources/Downloads2.php
Line: 5478



The code in question (lines 5476-5478) from the Downloads2.php file is:

Code: [Select]
// Insert the category
$smcFunc['db_query']('',"INSERT INTO smf_down_cat
(title, description, ID_PARENT)
VALUES ('$title', '$description',$ID_PARENT)");


I suspected that it might be an errant or missing single quote... something obvious. I also noticed that the field name in the database for ID_PARENT is lower case, not upper case. Tried changing that but no luck.  I'm clueless on this one.

Help please.



Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15765
    • View Profile
Re: Importing TP Portal Files Error
« Reply #1 on: February 21, 2010, 11:51:23 pm »

Find
Code: [Select]
$smcFunc['db_query']('',"INSERT INTO smf_down_cat
(title, description, ID_PARENT)
VALUES ('$title', '$description',$ID_PARENT)");
Before add
Code: [Select]
$title = mysql_escape_string($title);
$description = mysql_escape_string($description);
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline Pegasys

  • Member
  • *
  • Posts: 10
    • View Profile
Re: Importing TP Portal Files Error
« Reply #2 on: February 22, 2010, 12:58:24 am »
Thanks for the response.

Unfortunately, that didn't work. It just moved the line where the error occurred down a few lines... but still the same line of code.


* Cleared cache & power refreshed before re-running. Just to be sure.


Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15765
    • View Profile
Re: Importing TP Portal Files Error
« Reply #3 on: February 22, 2010, 10:15:18 am »
My guess would be some reason ID_PARENT is missing or is nothing in that example I would do an echo for the title, description, ID_PARENT to see what is trying to do

echo "INSERT INTO smf_down_cat
            (title, description, ID_PARENT)
         VALUES ('$title', '$description',$ID_PARENT)";
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline Pegasys

  • Member
  • *
  • Posts: 10
    • View Profile
Re: Importing TP Portal Files Error
« Reply #4 on: February 22, 2010, 12:41:36 pm »
Thats was EXTREMELY helpful !!  And it led directly to the solution.  

Per your suggestion, I put the  echo statement directly above the code in question so it would show us the data before the error popped Eg:

Code: [Select]
echo "INSERT INTO smf_down_cat
            (title, description, ID_PARENT)
         VALUES ('$title', '$description',$ID_PARENT)";

$smcFunc['db_query']('',"INSERT INTO {db_prefix}down_cat
(title, description, id_parent)
VALUES ('$title', '$description',$ID_PARENT)");

Note: This really honks up the page format... but we're in the admin panel so who cares.


The query is in a WHILE loop so there are a bunch of INSERT queries.... such as:

Code: [Select]
INSERT INTO smf_down_cat (title, description, ID_PARENT) VALUES ('PEG Mayor Mode Mods', '',298)

INSERT INTO smf_down_cat (title, description, ID_PARENT) VALUES ('PEG Snow Mods', 'The collection  of mods that adds a Winter Wonderland effect to your cities.',298)

INSERT INTO smf_down_cat (title, description, ID_PARENT) VALUES ('OWW2 Patches', 'Optional Patches and fixes for the OWW2',)

The last one is the one we're interested in, of course... and we can see that the 3rd insert value is either NULL, empty or not set. Apparently, there is a difference. All the other INSERT queries listed had values, either 0 or the number of a parent category.


THE STEPS TO RESOLVE

The first thing I tried was to set the ID_PARENT field in the smf_down_cat table to allow NULLs.   Did not help.  So the problem $ID_PARENT value is not NULL.

That leaves either not set or empty. So we move up the code to where the value of $ID_PARENT is set. Staring at line 5467:

Code: [Select]
$ID_PARENT = 0;
// Get the new parent id
if ($catRow['parent'] != 0)
$ID_PARENT = $catArray[$catRow['parent']];

$title = $smcFunc['db_escape_string']($catRow['name']);
$description = $smcFunc['db_escape_string']($catRow['description']);

// Insert the category
$title = mysql_escape_string($title);
$description = mysql_escape_string($description);

echo "INSERT INTO smf_down_cat
            (title, description, ID_PARENT)
         VALUES ('$title', '$description',$ID_PARENT)";

$smcFunc['db_query']('',"INSERT INTO {db_prefix}down_cat
(title, description, id_parent)
VALUES ('$title', '$description',$ID_PARENT)");

The first line there ( $ID_PARENT = 0 ) should have set the variable. I have no explanation why it did not. But this code seems to somehow allow bad data (either empty or unset) to get through. By inserting a couple of seemingly redundant lines of code, the bad data doesn't slip through:


Code: [Select]
$ID_PARENT = 0;

// Get the new parent id

if ($catRow['parent'] != 0)

$ID_PARENT = $catArray[$catRow['parent']];


// ** NEW LINES TO FIX ISSUE **
                 if (empty($ID_PARENT))
$ID_PARENT = 0;

if (!isset($ID_PARENT))
$ID_PARENT = 0;



Not sure how the empty or not set value slipped through... but these two lines solved the issue.  The import function completed successfully.


Again... thanks a ton and half for the help. The thought of having to manually export & import all the data manually was aging me before my time.


** From my perspective...  ISSUE RESOLVED.








« Last Edit: February 22, 2010, 12:49:40 pm by Pegasys »

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15765
    • View Profile
Re: Importing TP Portal Files Error
« Reply #5 on: February 22, 2010, 01:08:19 pm »
Glad that worked will add that fix too! Thanks for all the time spent debugging it very strange that the parent could be null in TP.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline Pegasys

  • Member
  • *
  • Posts: 10
    • View Profile
Re: Importing TP Portal Files Error
« Reply #6 on: February 22, 2010, 02:23:12 pm »
The data came from the old TP version 0.97... and whatever quirk allowed the NULL may have been fixed in updated versions. That might explain why this is the first you have heard of this issue.


* I installed TP way back when it was close to brand new.  Very useful... but lots of bugs and quirks... with updates & fixes too few and far between.  So I modified it to the extreme to suit my needs, which worked quite well... but made applying updates when they finally did come a pure manual process. Many fixes in the updates I had already either fixed or coded around. And following the old sage advice, "If it a'int broke, don't fix it"... I continued to to use the modified older version.

It didn't come back to bite me in the butt... until now.   ;)




Now you wouldn't happen to have the table structure for the smf_down_pic table handy, would you?
* Sorry... I run a non-profit site and am too broke to go Pro.


Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15765
    • View Profile
Re: Importing TP Portal Files Error
« Reply #7 on: February 22, 2010, 02:44:50 pm »
I use this in pro
Code: [Select]
CREATE TABLE IF NOT EXISTS {$db_prefix}down_file_pic(
ID_PICTURE int(11) NOT NULL auto_increment,
ID_FILE int(11) NOT NULL default '0',
ID_MEMBER mediumint(8) unsigned NOT NULL default '0',
date int(10) unsigned NOT NULL default '0',
title tinytext,
description text,
views int(10) NOT NULL default '0',
filesize int(10) NOT NULL default '0',
orginalfilename tinytext,
thumbfilename tinytext,
mediumfilename tinytext,
filename tinytext,
approved tinyint(4) NOT NULL default '1',
height int(10) NOT NULL default '0',
width int(10) NOT NULL default '0',

PRIMARY KEY (ID_PICTURE)) TYPE=MyISAM
« Last Edit: February 22, 2010, 02:49:35 pm by SMFHacks »
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline Pegasys

  • Member
  • *
  • Posts: 10
    • View Profile
Re: Importing TP Portal Files Error
« Reply #8 on: February 22, 2010, 04:06:58 pm »
Mucho Obligato.


 

Related Topics

  Subject / Started by Replies Last post
1 Replies
2912 Views
Last post December 09, 2007, 10:14:16 pm
by SMFHacks
0 Replies
2894 Views
Last post May 04, 2008, 08:57:46 am
by newguyatthis
3 Replies
4067 Views
Last post May 05, 2009, 07:24:06 pm
by SMFHacks
7 Replies
5590 Views
Last post June 11, 2009, 09:50:27 pm
by SMFHacks
1 Replies
1954 Views
Last post February 26, 2013, 05:20:08 pm
by SMFHacks

+- Recent Topics

Logo and Category? by tank_fv101
January 10, 2022, 08:03:11 am

Questions about SMF Gallery Pro Folders and Gallery URL by scso1502
January 05, 2022, 03:48:27 pm

$subcats_linktree by mickjav
January 05, 2022, 03:08:29 pm

New Photos Won't Upload - Gallery Pro 8.0 or 9.0b - Old Photos Still Visible by scso1502
January 05, 2022, 02:23:16 pm

Additional Recommendations for SMF Store by SMFHacks
January 03, 2022, 02:37:10 pm

Seasons Greetings by SMFHacks
December 24, 2021, 10:02:42 pm

Problems with the contact mod by SMFHacks
December 22, 2021, 09:16:24 am

Gallery Pro v8.0 and PHP 7.4 by SMFHacks
December 16, 2021, 01:34:03 pm

Thanks mod SMF 2.1 by Monocero
November 27, 2021, 01:13:01 pm

How to change the font on a photo in SMF Gallery Pro? by SMFHacks
November 18, 2021, 09:28:11 am

Powered by EzPortal