Jump to content

[SOLVED] [help] PHP DATABASE HELP


Tagette

Recommended Posts

<?php

 

//The purpose of this is to build an xml document so I can relay the information to a flash file

 

error_reporting(0); //Stops errors from poping up and messing up flash

 

$char = $_GET['char']; //uses GET method to access name from previous page

$error = 0;

 

$con = mysql_connect("host","user","pass");

if (!$con) {

$error++;

}

$db = mysql_select_db("db_name");

if (!$db) {

$error++;

}

echo "<?xml version=\"1.0\"?>\n"; //Makes it an official xml file

echo "<character>\n"; //Open tag for character information

 

//Problem is that when I go to the page, the php file does not get information from the database like it should.

//I did have correct connection information, but for for obvious reasons I removed them. So thats not the problem.

 

$query = 'SELECT * FROM characters WHERE name="'.$char.'"'; //I expect only one outcome from this query

$results = mysql_query($query);

$row = mysql_fetch_assoc($results); // I've tried both mysql_fetch_assoc and mysql_fetch_array here. Niether work.

 

$name = $row['name'];   //These return no value \/

$gender = $row['gender'];

$job = $row['job'];

$level = $row['level'];

$hp = $row['maxhp'];

$mp = $row['maxmp'];

$exp = $row['exp'];

$fame = $row['fame'];

$str = $row['str'];

$dex = $row['dex'];

$int = $row['int'];

$luk = $row['luk'];

$money = $row['money'];

$guildid = $row['guildid'];   //These return no value /\

 

 

$query2 = 'SELECT * FROM guilds WHERE guildid="'.$guildid.'"'; //I expect only one outcome from this query also

$results2 = mysql_query($query2);

$row2 = mysql_fetch_assoc($results2); // I've also tried both mysql_fetch_assoc and mysql_fetch_array here niether work

 

$guildname = $row2['name'];

 

if($error==0){

echo "\t<info>1</info>\n";

echo "\t<info>".$name."</info>\n";   //The php variables dont hold any values for some reason \/

echo "\t<info>".$gender."</info>\n";

echo "\t<info>".$job."</info>\n";

echo "\t<info>".$level."</info>\n";

echo "\t<info>".$hp."</info>\n";

echo "\t<info>".$mp."</info>\n";

echo "\t<info>".$exp."</info>\n";

echo "\t<info>".$fame."</info>\n";

echo "\t<info>".$str."</info>\n";

echo "\t<info>".$dex."</info>\n";

echo "\t<info>".$int."</info>\n";

echo "\t<info>".$luk."</info>\n";

echo "\t<info>".$money."</info>\n";

echo "\t<info>".$guildname."</info>\n";   //The php variables dont hold any values for some reason /\

}else{

echo "<info>0</info>\n";

echo "<info>Cannot connect.</info>\n";

}

 

echo "</character>\n"; //Closing tag for character information

 

mysql_close($con);

?>

 

Whats happening:

 

<?xml version="1.0"?>

<character>

<info>1</info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

<info></info>

</character>

 

What should happen:

 

<?xml version="1.0"?>

<character>

<info>1</info>

<info>Scarlet</info> //name

<info>0</info>  //gender

<info>522</info> //job

<info>255</info> //level

<info>30000</info> //hp

<info>30000</info> //mp

<info>26455161518</info> //exp

<info>1337</info> //fame

<info>32767</info> //str

<info>32767</info> //dex

<info>32767</info> //int

<info>32767</info> //luk

<info>2000000000</info> //money

<info>BossGuild</info> //guildname

</character>

 

Can someone help please I'm new at php. Thanks a lot.

Link to comment
https://forums.phpfreaks.com/topic/155937-solved-help-php-database-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.