Jump to content
php.lv forumi

no XML faila uz SQL datubāzi


reGative

Recommended Posts

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...

Link to comment
Share on other sites

  • Replies 30
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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;

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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 by mixis
Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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 by rATRIJS
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...