Jump to content

Something is wrong PHP


kworld

Recommended Posts

When the webpage loads it inserts all its information via xml into the database.

This all works fine and perfect untill i reload the page again then it starts screwing up all the data im not sure what im doing wrong i know this isnt much info but is there a common mistake im making?

Link to comment
Share on other sites

Heres all the code, i cant see what i'm doing wrong, it works fine at first but if i reload page it doesn't.

<?php
include 'connect.php';

$query = "SELECT * FROM pilot_tbl";
$results = mysql_query($query)
     or die(mysql_error());

while ($row = mysql_fetch_assoc($results)) {
$CharID = $row['CharID'];
$UserID = $row['UserID'];
$ApiKey = $row['ApiKey'];
$CharN = $row['CharN'];

$file="http://api.eve-online.com/char/FacWarStats.xml.aspx?apikey=$ApiKey&characterID=$CharID&userID=$UserID";
//$file="FacWarStats.xml.aspx.xml";
$get = file_get_contents($file);
$xml = new SimpleXMLElement($get);

if ($xml->result)
{
foreach($xml->result->currentRank as $dcrank);{
foreach($xml->result->highestRank as $dhrank);{
foreach($xml->result->killsYesterday as $dykills);{
foreach($xml->result->killsLastWeek as $dlwkills);{
foreach($xml->result->killsTotal as $dtkills);{
foreach($xml->result->victoryPointsYesterday as $dvypoints);{
foreach($xml->result->victoryPointsLastWeek as $dvlwpoints);{
foreach($xml->result->victoryPointsTotal as $dvtpoints);{

$query1 = "SELECT * FROM pstats WHERE charid='$CharID'";
$results1 = mysql_query($query1);
$row1 = mysql_fetch_array($results1);

				if ($row1)
				{
				extract ($row1);
				$query2 = "UPDATE pstats SET Crank = '$dcrank', Hrank = '$dhrank', Ykills = '$dykills', LWkills = '$dlwkills', Tkills = '$dtkills', VYpoints = '$dvypoints', VLWpoints = '$dvlwpoints' ,VTpoints = '$dvtpoints'";
					$insert2 = mysql_query($query2)
              	    	or (mysql_error());	
				}
				if (!$row1)
				{
				$query2 = "INSERT INTO pstats (charid, CharN, Crank, Hrank, Ykills, LWkills, Tkills, VYpoints, VLWpoints, VTpoints)
        				 			VALUES (
								'$CharID',
					 			'$CharN',
	    			 			'$dcrank',
	    			 			'$dhrank',
								'$dykills',
								'$dlwkills',	
								'$dtkills',
								'$dvypoints',
								'$dvlwpoints',					
	 		 					'$dvtpoints')";
         	     					$insert2 = mysql_query($query2)
           	 						or (mysql_error());
				}
}}}}}}}}
}
}
?>

Link to comment
Share on other sites

$query2 = "UPDATE pstats SET Crank = '$dcrank', Hrank = '$dhrank', Ykills = '$dykills', LWkills = '$dlwkills', Tkills = '$dtkills', VYpoints = '$dvypoints', VLWpoints = '$dvlwpoints' ,VTpoints = '$dvtpoints'";
					$insert2 = mysql_query($query2)

 

This is likely your problem. You don't have a WHERE clause so it will UPDATE everything.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

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