PHP Forum

PHP Forum (http://www.selfphp.de/forum/index.php)
-   MySQLi/PDO/(MySQL) (http://www.selfphp.de/forum/forumdisplay.php?f=22)
-   -   Datenübergabe Array -> Datenbank (http://www.selfphp.de/forum/showthread.php?t=25805)

Bengelbaer 15.03.2016 16:43:00

Datenübergabe Array -> Datenbank
 
Hy,

ich bin Michael und Baujahr 1979. Ich arbeite normalerweise im Vertrieb von Werkzeugen, und programmiere nur hobbymäßig etwas.

Hierzu setze ich mir immer Ziele welche ich erreichen möchte.

Aktuell versuche ich Kategorien aus einem Array in eine Datenbank zu schreiben.

Aber irgendwie haut was nicht hin, und ich bin grad etwas betriebsblind.

Daher würde es mich freuen wenn einer mal kurz drüber schauen könnte.

PHP-Code:

$conn = new mysqli($zDbHost$zDbUser$zDbPass$zDbDb);

                    
/* check connection */
if ($conn->connect_error) {
    die(
"Connection failed: " $mysqli->connect_error);

//////////////////////////////////////////Schleife für Kategorienerstellung////////////////////////////////////
foreach ($xmlstr->Items->Item as $row) {
        
$date date("Y-m-d H:i:s");
        
$MainCategorie $row->Main_ProductGroup;

                
$queryMainKat "INSERT INTO s_categories (id, 
                                                            parent,
                                                            path,
                                                            description,
                                                            position,
                                                            left,
                                                            right,
                                                            level,
                                                            added,
                                                            changed,
                                                            metakeywords,
                                                            metadescription,
                                                            cmsheadline,
                                                            cmstext,
                                                            template,
                                                            noviewselect,
                                                            active,
                                                            blog,
                                                            showfiltergroups,
                                                            external,
                                                            hidefilter,
                                                            hidetop,
                                                            mediaID,
                                                            product_box_layout,
                                                            meta_title,
                                                            stream_id)

                                                            VALUES 
                                                            
                                                            ('',
                                                            '"
.$hauptKatId."',
                                                            '|"
.$hauptKatId."|',
                                                            '"
.$MainCategorie."',
                                                            NULL,
                                                            '0',
                                                            '0',
                                                            '0',
                                                            '"
.$date."',
                                                            '"
.$date."',
                                                            NULL,
                                                            '',
                                                            '',
                                                            '',
                                                            'article_listing_4col.tpl',
                                                            '0',
                                                            '1',
                                                            '0',
                                                            '1',
                                                            '',
                                                            '0',
                                                            '0',
                                                            NULL,
                                                            'basic',
                                                            '',
                                                            NULL )"
;
                if (
$conn->query($queryMainKat) === TRUE) {
                    echo 
"New record created successfully";
                    } else {
                    echo 
"Error: " $queryMainKat "<br>" $conn->error;}

                
$MainKatId "Select id from s_categories where description = '" $MainCategorie "'";
                if (
$conn->query($MainKatId) === TRUE) {
                    echo 
"New record found successfully";
                    } else {
                    echo 
"Error: " $MainKatId "<br>" $conn->error;}

                
$queryMainKat_attr "INSERT INTO s_categories_attributes (id,categoryID,attribute1,attribute2,attribute3,attribute4,attribute5,attribute6) VALUES (NULL,'".$MainKatId."','','','','','','' )";
                if (
$conn->query($queryMainKat_attr) === TRUE) {
                    echo 
"New record created successfully";
                    } else {
                    echo 
"Error: " $queryMainKat_attr "<br>" $conn->error;}
                 
                echo 
$conn->error;
                
///Durchlaufbegrenzung                        
                    
if ($i==3) break;
                    
$i++;    
}; 

und hier die Ausgabe

Code:

Error: INSERT INTO s_categories (id, parent, path, description, position, left, right, level, added, changed, metakeywords, metadescription, cmsheadline, cmstext, template, noviewselect, active, blog, showfiltergroups, external, hidefilter, hidetop, mediaID, product_box_layout, meta_title, stream_id) VALUES ('', '3', '|3|', 'Lebensmittelbeutel aus Papier ', NULL, '0', '0', '0', '2016-03-15 15:33:13', '2016-03-15 15:33:13', NULL, '', '', '', 'article_listing_4col.tpl', '0', '1', '0', '1', '', '0', '0', NULL, 'basic', '', NULL )
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 'left, right, level, added, ' at line 6Error: Select id from s_categories where description = 'Lebensmittelbeutel aus Papier '
Error: INSERT INTO s_categories_attributes (id,categoryID,attribute1,attribute2,attribute3,attribute4,attribute5,attribute6) VALUES (NULL,'Select id from s_categories where description = 'Lebensmittelbeutel aus Papier '','','','','','','' )
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 'Lebensmittelbeutel aus Papier '','','','','','','' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Lebensmittelbeutel aus Papier '','','','','','','' )' at line 1Error: INSERT INTO s_categories (id, parent, path, description, position, left, right, level, added, changed, metakeywords, metadescription, cmsheadline, cmstext, template, noviewselect, active, blog, showfiltergroups, external, hidefilter, hidetop, mediaID, product_box_layout, meta_title, stream_id) VALUES ('', '3', '|3|', 'Servietten "ROYAL Collection"', NULL, '0', '0', '0', '2016-03-15 15:33:13', '2016-03-15 15:33:13', NULL, '', '', '', 'article_listing_4col.tpl', '0', '1', '0', '1', '', '0', '0', NULL, 'basic', '', NULL )
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 'left, right, level, added, ' at line 6Error: Select id from s_categories where description = 'Servietten "ROYAL Collection"'
Error: INSERT INTO s_categories_attributes (id,categoryID,attribute1,attribute2,attribute3,attribute4,attribute5,attribute6) VALUES (NULL,'Select id from s_categories where description = 'Servietten "ROYAL Collection"'','','','','','','' )
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 'Servietten "ROYAL Collection"'','','','','','','' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Servietten "ROYAL Collection"'','','','','','','' )' at line 1Error: INSERT INTO s_categories (id, parent, path, description, position, left, right, level, added, changed, metakeywords, metadescription, cmsheadline, cmstext, template, noviewselect, active, blog, showfiltergroups, external, hidefilter, hidetop, mediaID, product_box_layout, meta_title, stream_id) VALUES ('', '3', '|3|', 'Servietten "ROYAL Collection"', NULL, '0', '0', '0', '2016-03-15 15:33:13', '2016-03-15 15:33:13', NULL, '', '', '', 'article_listing_4col.tpl', '0', '1', '0', '1', '', '0', '0', NULL, 'basic', '', NULL )
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 'left, right, level, added, ' at line 6Error: Select id from s_categories where description = 'Servietten "ROYAL Collection"'
Error: INSERT INTO s_categories_attributes (id,categoryID,attribute1,attribute2,attribute3,attribute4,attribute5,attribute6) VALUES (NULL,'Select id from s_categories where description = 'Servietten "ROYAL Collection"'','','','','','','' )
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 'Servietten "ROYAL Collection"'','','','','','','' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Servietten "ROYAL Collection"'','','','','','','' )' at line 15.997079 Sekunden


vermutlich ist es ein einfacher Fehler.

Vielen Dank schon mal.

Bengelbaer 15.03.2016 17:12:42

AW: Datenübergabe Array -> Datenbank
 
Konnte es nun selbst lösen.

PHP-Code:

foreach ($xmlstr->Items->Item as $row) {
        
$date date("Y-m-d H:i:s");
        
$MainCategorie $row->Main_ProductGroup;

                
$queryMainKat "INSERT INTO `s_categories` (`id`, 
                                                            `parent`,
                                                            `path`,
                                                            `description`,
                                                            `position`,
                                                            `left`,
                                                            `right`,
                                                            `level`,
                                                            `added`,
                                                            `changed`,
                                                            `metakeywords`,
                                                            `metadescription`,
                                                            `cmsheadline`,
                                                            `cmstext`,
                                                            `template`,
                                                            `noviewselect`,
                                                            `active`,
                                                            `blog`,
                                                            `showfiltergroups`,
                                                            `external`,
                                                            `hidefilter`,
                                                            `hidetop`,
                                                            `mediaID`,
                                                            `product_box_layout`,
                                                            `meta_title`,
                                                            `stream_id`)

                                                            VALUES 
                                                            
                                                            ('',
                                                            '"
.$hauptKatId."',
                                                            '|"
.$hauptKatId."|',
                                                            '"
.$MainCategorie."',
                                                            NULL,
                                                            '0',
                                                            '0',
                                                            '0',
                                                            '"
.$date."',
                                                            '"
.$date."',
                                                            NULL,
                                                            '',
                                                            '',
                                                            '',
                                                            'article_listing_4col.tpl',
                                                            '0',
                                                            '1',
                                                            '0',
                                                            '1',
                                                            '',
                                                            '0',
                                                            '0',
                                                            NULL,
                                                            'basic',
                                                            '',
                                                            NULL )"
;
                if (
$conn->query($queryMainKat) === TRUE) {
                    echo 
"New record created successfully";
                    } else {
                    echo 
"Error: " $queryMainKat "<br>" $conn->error;}

                
$MainKatId "Select `id` from `s_categories` where `description` = '$MainCategorie'";
                if (
$conn->query($MainKatId) === TRUE) {
                    echo 
"New record found successfully";
                    } else {
                    echo 
"Error: " $MainKatId "<br>" $conn->error;}

                
$queryMainKat_attr "INSERT INTO `s_categories_attributes` (`id`,`categoryID`,`attribute1`,`attribute2`,`attribute3`,`attribute4`,`attribute5`,`attribute6`) VALUES (NULL,'".$MainKatId."','','','','','','' )";
                if (
$conn->query($queryMainKat_attr) === TRUE) {
                    echo 
"New record created successfully";
                    } else {
                    echo 
"Error: " $queryMainKat_attr "<br>" $conn->error;}
                 
                echo 
$conn->error;
                
///Durchlaufbegrenzung                        
                    
if ($i==3) break;
                    
$i++;    
}; 


immer diese `````````````````````````


nur hier hakt jetzt noch etwas

PHP-Code:

                $MainKatId "Select `id` from `s_categories` where `description` = '$MainCategorie'"
                if (
$conn->query($MainKatId) === TRUE) { 
                    echo 
"New record found successfully"
                    } else { 
                    echo 
"Error: " $MainKatId "<br>" $conn->error;} 

aktuelle fehlermeldung

Code:

New record created successfullyError: Select `id` from `s_categories` where `description` = 'Lebensmittelbeutel aus Papier '
Error: INSERT INTO `s_categories_attributes` (`id`,`categoryID`,`attribute1`,`attribute2`,`attribute3`,`attribute4`,`attribute5`,`attribute6`) VALUES (NULL,'Select `id` from `s_categories` where `description` = 'Lebensmittelbeutel aus Papier '','','','','','','' )
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 'Lebensmittelbeutel aus Papier '','','','','','','' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Lebensmittelbeutel aus Papier '','','','','','','' )' at line 1New record created successfullyError: Select `id` from `s_categories` where `description` = 'Servietten "ROYAL Collection"'
Error: INSERT INTO `s_categories_attributes` (`id`,`categoryID`,`attribute1`,`attribute2`,`attribute3`,`attribute4`,`attribute5`,`attribute6`) VALUES (NULL,'Select `id` from `s_categories` where `description` = 'Servietten "ROYAL Collection"'','','','','','','' )
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 'Servietten "ROYAL Collection"'','','','','','','' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Servietten "ROYAL Collection"'','','','','','','' )' at line 1New record created successfullyError: Select `id` from `s_categories` where `description` = 'Servietten "ROYAL Collection"'
Error: INSERT INTO `s_categories_attributes` (`id`,`categoryID`,`attribute1`,`attribute2`,`attribute3`,`attribute4`,`attribute5`,`attribute6`) VALUES (NULL,'Select `id` from `s_categories` where `description` = 'Servietten "ROYAL Collection"'','','','','','','' )
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 'Servietten "ROYAL Collection"'','','','','','','' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Servietten "ROYAL Collection"'','','','','','','' )' at line 13.990295 Sekunden


vt1816 15.03.2016 17:20:29

AW: Datenübergabe Array -> Datenbank
 
Hallo und willkommen hier im Forum.


Beschäftige Dich mit der Problematik der reservierten Wörter in MySQL, setze die Feldnamen in `` (Backticks) und maskiere die Hochkomma in der Artikelbeschreibung u.a.
Weitere Ausführungen findest Du auch hier (Typische Fehlerquellen im SQL).

PS: Für eine bessere Lesbarkeit der Fehlermeldung arbeite bitte mit Zeilenumbrüchen und trenne Fehlermeldungen.


Alle Zeitangaben in WEZ +2. Es ist jetzt 11:06:08 Uhr.

Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.