reGative Posted May 17, 2011 Author Report Share Posted May 17, 2011 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 1 - tāds errors. Un uzrāda, ka "undefined variable". Un šo XML man iedeva WordPress dzinis... Quote Link to comment Share on other sites More sharing options...
daGrevis Posted May 17, 2011 Report Share Posted May 17, 2011 Varētu sākt ar to, ka... 1) Izvāc to mysql_connect() un mysql_select_db() no cikla, 2) Aizver ciklu ar }, 3) Saproti, ka mainīgais $ievads nav definēts; Quote Link to comment Share on other sites More sharing options...
reGative Posted May 17, 2011 Author Report Share Posted May 17, 2011 Man takš visi cikli tur ir ciet. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted May 17, 2011 Report Share Posted May 17, 2011 Ak jel... kas par murgu! He, he. Nedomāju, ka tādu kodu var uzrakstīt, tāpēc sajaucu... Pseido-kods: 1) Iegūstam datus no XML, 2) Savienojamies ar datubāzi, 3) Tik daudz reizes, cik ierakstu ir iegūtajos datos, izpildām ciklu un katru reizi veicam pieprasījumu uz datubāzi; Quote Link to comment Share on other sites More sharing options...
reGative Posted May 17, 2011 Author Report Share Posted May 17, 2011 <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); $xml = simplexml_load_file("xml.xml"); $con = mysql_connect("localhost","root",""); if (!$con) { die('Nav iespejams pieslegties: ' . mysql_error()); } foreach ($xml->item as $item) { $id = $item ->post_id; $virsraksts = $item->title; $teksts = $item->encoded; mysql_select_db("dienasgramata", $con); mysql_query("INSERT INTO ieraksti(id, virsraksts,teksts) VALUES ($id, $virsraksts, $teksts)") or die(mysql_error()); } ?> kkā tā? nekas neiet un raksti nesūtās. Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted May 17, 2011 Report Share Posted May 17, 2011 Veertiibas vaicaajumaa ir jaaliek peedinjaas. Jaaizmanto ir mysql_real_escape_string. Paarbaudi vai tev tas XML fails vispaar ir nolasiits http://uk3.php.net/simplexml_load_file un http://uk2.php.net/var_dump + paarbaudi vai tev tas cikls vispaar izpildaas... Un beidz izpildiit mysql_select_db ciklaa!!! Kaa jau teicu - saac ar pamatiem... Quote Link to comment Share on other sites More sharing options...
mixis Posted May 18, 2011 Report Share Posted May 18, 2011 (edited) Nepārbaudīju vai strādā, bet pielaboju pašas acīmredzamākās kļūdas <?php $xml = simplexml_load_file("xml.xml"); $con = mysql_connect("localhost","root",""); if (!$con) { die('Nav iespejams pieslegties: ' . mysql_error()); } mysql_select_db("dienasgramata", $con); foreach ($xml->item as $item) { $id = $item ->post_id; $virsraksts = $item->title; $teksts = $item->encoded; mysql_query("INSERT INTO ieraksti(id, virsraksts, ievads, teksts) VALUES ($id, $virsraksts, $ievads, $teksts)"); ?> } ?> un vel klāt jāpieliek tas ko @rATRIJS raksta Edited May 18, 2011 by mixis Quote Link to comment Share on other sites More sharing options...
reGative Posted May 18, 2011 Author Report Share Posted May 18, 2011 problēma ir tur, ka tur ir, piem, content:encoded, kā man to uzrakstīt php? Quote Link to comment Share on other sites More sharing options...
reGative Posted May 18, 2011 Author Report Share Posted May 18, 2011 un nestrādā. Uzliku debugging, neko nerāda. Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted May 18, 2011 Report Share Posted May 18, 2011 (edited) Tu vēl, gandrīz 2 gadu laikā, tā arī neesi iemācījies, ka string vērtības, mysql pieprasījumos jāliek starp ''? Edited May 18, 2011 by xPtv45z Quote Link to comment Share on other sites More sharing options...
daGrevis Posted May 18, 2011 Report Share Posted May 18, 2011 Kā var "uzlikt debugging"? Quote Link to comment Share on other sites More sharing options...
reGative Posted May 18, 2011 Author Report Share Posted May 18, 2011 Kā var "uzlikt debugging"? ar or die(mysql_error()); ini_set('display_errors', 'On'); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted May 18, 2011 Report Share Posted May 18, 2011 Iemācies pats testēt. var_dump($xml); - apskaties vai vispār nolasa xml. echo $sql, apskaties kādi veidojas sql pieprasījumi, pamēģini viņus pats izpildīt phpmyadmina vai kas tev tur ir. Quote Link to comment Share on other sites More sharing options...
reGative Posted May 18, 2011 Author Report Share Posted May 18, 2011 Tātad, ir kods pašlaik šāds - <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); if (file_exists('xml.xml')) { $xml = simplexml_load_file('xml.xml'); } else { exit('Failed to open test.xml.'); } $con = mysql_connect("localhost","root",""); if (!$con) { die('Nav iespejams pieslegties: ' . mysql_error()); } mysql_select_db("dienasgramata", $con); foreach ($xml->item as $item) { $id = mysql_real_escape_string($item) ->post_id; $virsraksts = mysql_real_escape_string($item)->title; $teksts = mysql_real_escape_string($item)->encoded; $m_q = mysql_query("INSERT INTO ieraksti(id, virsraksts, ievads, teksts) VALUES ('$id','$virsraksts','$ievads','$teksts')") or die(mysql_error()); if(!$m_q) { die('Kluda!'); } }?> bet vienalga neiet. un ieliku mysql_real_escape_string. Un nerāda to "Failed to open". Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted May 18, 2011 Report Share Posted May 18, 2011 (edited) WTF ir tas??? $id = mysql_real_escape_string($item) ->post_id; $virsraksts = mysql_real_escape_string($item)->title; $teksts = mysql_real_escape_string($item)->encoded; eniivei - spriezhot peec taa ka tev neizleca nekaadas kljuudas no mana augstaak piemineetaa WTF tad saku, ka tev tas cikls nemaz neizpildaas... btw saku tresho reizi - SAAC AR PAMATIEM!!! Edited May 18, 2011 by rATRIJS Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.