• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Compiling Convert Xml Accounts to SQL Problem

dunnish

New Member
Joined
Jun 18, 2009
Messages
268
Solutions
1
Reaction score
2
Hello! im trying to convert an old server with xml account to sql with all characters&accounts

index.php
PHP:
<?php
$conn = mysqli_connect("localhost", "root", "test", "tfs");

$affectedRow = 0;

$xml = simplexml_load_file("input.xml") or die("Error: Cannot create object");

foreach ($xml->children() as $row) {
    #$id = $row->id;
    #$name = $row->name;
    $world_id = $row->world_id;
    $group_id = $row->group_id;
    
    #$sql = "INSERT INTO tbl_tutorials(title,link,description,keywords) VALUES ('" . $title . "','" . $link . "','" . $description . "','" . $keywords . "')";
#,name,world_id,group_id,account_id,level,vocation,health,healthmax,experience,lookbody,lookfeet,lookhead,looklegs,looktype,lookaddons,maglevel,mana,manamax,manaspent,soul,town_id,posx,posy,posz,conditions,cap,sex,lastlogin,lastip,save,skull,skulltime,rank_id,guildnick,lastlogout,blessings,balance,stamina,direction,online,marriage,promotion,deleted,description,kills,deaths,assists,create_ip,create_date,hide_char,comment,country,tmp_kills,tmp_assists,tmp_deaths
     $sql = "INSERT INTO `players` (name) VALUES ('" . $name . "')";
    $result = mysqli_query($conn, $sql);
    
    if (! empty($result)) {
        $affectedRow ++;
    } else {
        $error_message = mysqli_error($conn) . "\n";
    }
}
?>
<h2>Insert XML Data to MySql Table Output</h2>
<?php
if ($affectedRow > 0) {
    $message = $affectedRow . " records inserted";
} else {
    $message = "No records inserted";
}

?>
<style>
body { 
    max-width:550px;
    font-family: Arial;
}
.affected-row {
    background: #cae4ca;
    padding: 10px;
    margin-bottom: 20px;
    border: #bdd6bd 1px solid;
    border-radius: 2px;
    color: #6e716e;
}
.error-message {
    background: #eac0c0;
    padding: 10px;
    margin-bottom: 20px;
    border: #dab2b2 1px solid;
    border-radius: 2px;
    color: #5d5b5b;
}
</style>
<div class="affected-row"><?php  echo $message; ?></div>
<?php if (! empty($error_message)) { ?>
<div class="error-message"><?php echo nl2br($error_message); ?></div>
<?php } ?>

input.xml
XML:
<?xml version="1.0"?>
                    <player name="Will Hunting" world_id="0" account_id="1" sex="3" lookdir="0" exp="105764511" vocation="1" level="187" group_id="0" cap="300" maglevel="55" lastlogin="1159037839" premticks="0" promoted="0" banned="0"><spawn x="1004" y="574" z="6"/><temple x="1004" y="574" z="6"/><skull type="4" kills="0" ticks="0" absolve="0"/><health now="1080" max="1080" food="0"/><mana now="5405" max="5405" spent="0"/><look type="130" head="78" body="132" legs="114" feet="125"/><skills><skill skillid="0" level="10" tries="0"/><skill skillid="1" level="10" tries="0"/><skill skillid="2" level="10" tries="0"/><skill skillid="3" level="10" tries="0"/><skill skillid="4" level="10" tries="0"/><skill skillid="5" level="10" tries="0"/><skill skillid="6" level="10" tries="0"/></skills><spells/><deaths/><inventory><slot slotid="1"><item id="2498" /></slot><slot slotid="2"><item id="2198" /></slot><slot slotid="3"><item id="1988" ><inside><item id="1993" ><inside><item id="2305" count="100" /><item id="2261" count="1" /><item id="2305" count="100" /><item id="2261" count="100" /><item id="2305" count="100" /><item id="2261" count="100" /><item id="2305" count="100" /><item id="2261" count="100" /></inside></item><item id="1995" ><inside><item id="2293" count="100" /><item id="2293" count="100" /><item id="2293" count="100" /><item id="2293" count="100" /><item id="2293" count="100" /><item id="2293" count="100" /><item id="2293" count="100" /><item id="2293" count="100" /></inside></item><item id="1988" ><inside><item id="2164"/><item id="2164"/><item id="2164"/><item id="2164"/><item id="2169" time="600000"/><item id="2198" /><item id="2169" time="600000"/><item id="2197" /><item id="2169" time="600000"/><item id="2197" /><item id="2169" time="600000"/><item id="2197" /><item id="2546" count="100"/><item id="2546" count="100"/><item id="2546" count="100"/><item id="2546" count="100"/></inside></item><item id="2004" ><inside><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2004" ><inside><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2004" ><inside><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7" /><item id="2006" count="7"/></inside></item></inside></item></inside></item><item id="2001" ><inside><item id="2313" count="100" /><item id="2313" count="100" /><item id="2313" count="100"/><item id="2313" count="100" /><item id="2313" count="100"/><item id="2313" count="100" /><item id="2313" count="100" /><item id="2313" count="100" /><item id="2313" count="100"/><item id="2313" count="100" /><item id="2313" count="100"/><item id="2313" count="100" /><item id="2313" count="100" /><item id="2313" count="100" /><item id="2313" count="100"/><item id="2313" count="100" /><item id="2313" count="100" /><item id="2313" count="100"/><item id="2313" count="100" /><item id="2313" count="100" /></inside></item><item id="2003" ><inside><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/><item id="2268" count="100"/></inside></item><item id="2002" ><inside><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/><item id="2273" count="100"/></inside></item></inside></item></slot><slot slotid="4"><item id="2656" /></slot><slot slotid="6"><item id="2456"/></slot><slot slotid="7"><item id="2477" /></slot><slot slotid="8"><item id="2195" /></slot><slot slotid="10"><item id="2546" count="100"/></slot></inventory><depots><depot depotid="1"><item id="2590"><inside><item id="2594"/></inside></item></depot></depots><storage/></player>

but i get this as output
Duplicate entry '0' for key 'name'
its put empty as name can't figure out why.

and if i remove the "Duplicate" its just ad a new one with Empty name.
 

Attachments

Why don't you try converting xml file to sql using one of those fancy online converters. Then just upload sql to your database. You will probably get errors cause of items but it should populate other necessary fields??
 
Back
Top