Jump to content

[SOLVED] write an echo


mforan

Recommended Posts

i understand how to write something into the database, its just writing it to $data thats the problem. of course the reason i want to do this is because i want to add $data2 to $data.

 

then, write $data3

 

so in otherwords something like this:

 

echo to $data to $data + $data2 ($data3) to database

Link to comment
https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665374
Share on other sites

$data = "echo \"<a class='variable'>\".$losses[$i].\"</a> \".$unitnames[$i].\"s<br>\";";

 

When you pull the data out and want to execute it, assuming a variable called $evaluate has that code...

 

eval($evaluate);

 

 

 

tryed this, hasnt worked, just inputs nothing into the database.

Link to comment
https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665390
Share on other sites

<?php
$logs1 = "$warresult<br><br>BATTLE REPORT:<br>Your total AP: $totaltotal <font color=#FF0000>($el% losses)</font><br>Enemy total DP: $etotaltotal <font color=#00FF00>($ul% damage)</font><br><br>";

        echo $warresult."<br><br>BATTLE REPORT:<br>Your total AP: ".$totaltotal." <font color='#FF0000'>($el% losses)</font><br>Enemy total DP: ".$etotaltotal." <font color='#00FF00'>($ul% damage)</font><br><br>";
        $unitnames = array("T80","BMP","Mi-28","AH-64","RAH-66","F-16","F-117","F-22","B52","B2","ICBM","BML Submarine","Nuclear Missile","".$info[107]."");
	$unitnamese = array("T80","BMP","Mi-28","AH-64","RAH-66","F-16","F-117","F-22","B52","B2","ICBM","BML Submarine","Nuclear Missile","".$enemydet[107]."");
        $j = false;
        for ($i = 0; $i < 13; $i++) {
          if ($elosses[$i]) {
            if (!$j) {
              echo "You killed:<br>";
              $j = true;
            }
            echo "<a class='variable'>".$elosses[$i]."</a> enemy ".$unitnamese[$i]."s<br>";
          }
        }
        if ($j) { echo "<br>"; } else { echo "You killed <a class='variable'>0</a> enemy units<br><br>"; }

        $j = false;
        for ($i = 0; $i < 14; $i++) {
          if ($losses[$i]) {
            if (!$j) {
              echo "You lost:<br>";
              $j = true;
            }
            echo "<a class='variable'>".$losses[$i]."</a> ".$unitnames[$i]."s<br>";
          }
        }
        if ($j) { echo "<br>"; } else { echo "You lost <a class='variable'>0</a> units<br><br>"; }
        echo "<br><br>";?>

 

(edited by kenrbnsn to add the


tags)

Link to comment
https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665398
Share on other sites

i want all the data that is echo'd put into the database, which is why i said i needed $data to include the echo or "write the echo" as it is.

 

by database setup i assume you mean, how is it going to write it?

 

$query = "INSERT INTO attacks SET username='$user',log='$logs2'";
mysql_query($query) or die("Error: ".mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665407
Share on other sites

<?php

// everything get saved to the $data variable
$data = null;

$logs1 = "$warresult<br><br>BATTLE REPORT:<br>Your total AP: $totaltotal <font color=#FF0000>($el% losses)</font><br>Enemy total DP: $etotaltotal <font color=#00FF00>($ul% damage)</font><br><br>";

$data .= $warresult."<br><br>BATTLE REPORT:<br>Your total AP: ".$totaltotal." <font color='#FF0000'>($el% losses)</font><br>Enemy total DP: ".$etotaltotal." <font color='#00FF00'>($ul% damage)</font><br><br>";
        $unitnames = array("T80","BMP","Mi-28","AH-64","RAH-66","F-16","F-117","F-22","B52","B2","ICBM","BML Submarine","Nuclear Missile","".$info[107]."");
      $unitnamese = array("T80","BMP","Mi-28","AH-64","RAH-66","F-16","F-117","F-22","B52","B2","ICBM","BML Submarine","Nuclear Missile","".$enemydet[107]."");
        $j = false;
        for ($i = 0; $i < 13; $i++) {
          if ($elosses[$i]) {
            if (!$j) {
              $data .= "You killed:<br>";
              $j = true;
            }
            $data .= "<a class='variable'>".$elosses[$i]."</a> enemy ".$unitnamese[$i]."s<br>";
          }
        }

        $data .= ($j) ? "<br>" : "You killed <a class='variable'>0</a> enemy units<br><br>";

        $j = false;
        for ($i = 0; $i < 14; $i++) {
          if ($losses[$i]) {
            if (!$j) {
              $data .= "You lost:<br>";
              $j = true;
            }
            $data .= "<a class='variable'>".$losses[$i]."</a> ".$unitnames[$i]."s<br>";
          }
        }
        $data .= ($j) ? "<br>" : "You lost <a class='variable'>0</a> units<br><br>";
        $data .= "<br><br>";

        // display whats stored in the variable
        echo $data;

        // add data to database
        $query = "INSERT INTO attacks SET username='$user',log='$logs2', data='$data'";
        mysql_query($query) or die("Error: ".mysql_error());

?>

Something like that? You'll need to change your query though. I dont know you table structure.

Link to comment
https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665424
Share on other sites

i think this may work, i have 1 more problem thou. when it wrote to the database, it only stored:

 

You lost the battle<br><br>BATTLE REPORT:<br>Your total AP: 0 <font color=

 

in otherwords it didnt write '

 

which is also why i made:

$logs1 = "$warresult<br><br>BATTLE REPORT:<br>Your total AP: $totaltotal <font color=#FF0000>($el% losses)</font><br>Enemy total DP: $etotaltotal <font color=#00FF00>($ul% damage)</font><br><br>";

 

the one in the one you posted contains them:

$data .= $warresult."<br><br>BATTLE REPORT:<br>Your total AP: ".$totaltotal." <font color='#FF0000'>($el% losses)</font><br>Enemy total DP: ".$etotaltotal." <font color='#00FF00'>($ul% damage)</font><br><br>";

Link to comment
https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665435
Share on other sites

nope, its using text lol. :( il try varchar lol

NO! It should be TEXT.

 

Woops. This:

        $query = "INSERT INTO attacks SET username='$user',log='$logs2', data='$data'";
        mysql_query($query) or die("Error: ".mysql_error());

 

Should be

        $query = "INSERT INTO attacks SET username='$user',log='$logs2', data='".mysql_real_escape_string($data) . "'";
        mysql_query($query) or die("Error: ".mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665441
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.