mforan Posted October 14, 2008 Share Posted October 14, 2008 very simple, yet i dont know how to do it.... how do you write an echo to the database? i want to do this as i cant write an echo'd array into the database, its need to be entered as full text. Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/ Share on other sites More sharing options...
947740 Posted October 14, 2008 Share Posted October 14, 2008 Write an echo? Can you rephrase your question? Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665352 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 echo "blah<br><br>"; how do i make that be: $data Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665354 Share on other sites More sharing options...
947740 Posted October 14, 2008 Share Posted October 14, 2008 $data = "blah<br><br>"; Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665356 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 lol, no no no. i need the eco to be the $data, not the $data to be the echo, its quite easy to echo "$data"; Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665359 Share on other sites More sharing options...
947740 Posted October 14, 2008 Share Posted October 14, 2008 So...you want the variable to contain PHP script? Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665360 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 This is the exact code i need to write to the database: echo "<a class='variable'>".$losses[$i]."</a> ".$unitnames[$i]."s<br>"; excluding of course the echo and ". you see my problem now? Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665366 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 yyou cant write $data = "<a class='variable'>".$losses[$i]."</a> ".$unitnames[$i]."s<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665369 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 You'd do $var = 'your value here'; $sql = "INSERT INTO TABLE `table_name` SET `col_name`='$var'"; Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665370 Share on other sites More sharing options...
947740 Posted October 14, 2008 Share Posted October 14, 2008 $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); Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665373 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665374 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 Then you'd use the concatenation operator $var1 = 'Hello '; $var2 = 'World'; echo $var1 . $var2; or alternatively $var3 = $var1; $var3 .= $var2; echo $var3; Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665377 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 $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. Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665390 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 What was the query you used? You should also post the code you're using here. Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665392 Share on other sites More sharing options...
kenrbnsn Posted October 14, 2008 Share Posted October 14, 2008 Please show us the code you're using, without it we're just guess as to what you want. Ken Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665393 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 also just tryed $data = '<a class=variable>".$losses[$i]."</a> ".$unitnames[$i]."s<br>'; to no avail Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665394 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 <?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) Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665398 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 basically i need all those outputted echo's to be put somewhere, where i can add it to a text into the database. as it is so the user can view a report later on of the "attack", like a history Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665400 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 What variable/text do you want to saved to your database? Also how is your database setup? Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665404 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 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()); Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665407 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665424 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665435 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 This is most probably because you're using the incorrect data type for the data field in your database. Make sure you're using TEXT not VARCHAR Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665437 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 nope, its using text lol. il try varchar lol Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665439 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 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()); Quote Link to comment https://forums.phpfreaks.com/topic/128414-solved-write-an-echo/#findComment-665441 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.