Einzelnen Beitrag anzeigen
  #1  
Alt 15.03.2016, 15:43:00
Bengelbaer Bengelbaer ist offline
Anfänger
 
Registriert seit: Mar 2016
Alter: 44
Beiträge: 2
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.
Mit Zitat antworten