Jump to content

Archived

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

Julian

Help with eval();

Recommended Posts

Hi. I'm trying to obtain a value from the database and add 1, but I can't get this value. I tried eval(). But I think I'm doing something wrong, beacause I can get the result. Thanks for the help, here's the code:

$datoa = "\$row_".$_GET['Equipo']; // Blue
$datob = $_GET['Suceso'].$_GET['Gorra']; // Goal1
$datoc = $datoa."['".$datob."']".";"; // $row_Blue['Goal1'];
$varold = eval($datoc); // ? No results :(
$varnew = $varold + 1;

Thanks.

Share this post


Link to post
Share on other sites
Can you please clarify? What you want? Do you want to update the database right after?

You don't seem to be retrieving anything from a database...

Share this post


Link to post
Share on other sites
Thanks poirot.

Here's what I'm doing:

First I get the info from to the database with this:

//Blancos
$colname_Blanco = "1";
if (isset($_GET['Encuentro'])) {
$colname_Blanco = (get_magic_quotes_gpc()) ? $_GET['Encuentro'] : addslashes($_GET['Encuentro']);
}
mysql_select_db($database_waterpolo, $waterpolo);
$query_Blanco = sprintf("SELECT * FROM Blanco WHERE Encuentro = %s", $colname_Blanco);
$Blanco = mysql_query($query_Blanco, $waterpolo) or die(mysql_error());
$row_Blanco = mysql_fetch_assoc($Blanco);
$totalRows_Blanco = mysql_num_rows($Blanco);

//Azules
$colname_Azul = "1";
if (isset($_GET['Encuentro'])) {
$colname_Azul = (get_magic_quotes_gpc()) ? $_GET['Encuentro'] : addslashes($_GET['Encuentro']);
}
mysql_select_db($database_waterpolo, $waterpolo);
$query_Azul = sprintf("SELECT * FROM Azul WHERE Encuentro = %s", $colname_Azul);
$Azul = mysql_query($query_Azul, $waterpolo) or die(mysql_error());
$row_Azul = mysql_fetch_assoc($Azul);
$totalRows_Azul = mysql_num_rows($Azul);



There're 2 different tables 1 for "Blancos" and 1 for "Azules".

I'm trying to update the info of the goals for every table Gol+Cap Number. But first I have to get the info from the database to update it.

I $_Get the info from a form and then tried to update de database. Here's what I tried:

$dato = $_GET['Equipo'];
$datoa = "\$row_".$_GET['Equipo'];
$datob = $_GET['Suceso'].$_GET['Gorra'];
$datoc = $datoa."['".$datob."']".";";
$varold = eval($datoc);
$varnew = $varold + 1;


if ((isset($_GET["MM_update"])) && ($_GET["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE $dato SET $datob=$varnew WHERE Encuentro=%s",
GetSQLValueString($datob , "int"));

mysql_select_db($database_waterpolo, $waterpolo);
$Result2 = mysql_query($updateSQL, $waterpolo) or die(mysql_error());


The value I trying to obtain is $datoc in order to update de database.

Thanks for the help.

Share this post


Link to post
Share on other sites
here's part of your problem:
[quote]
A return statement will terminate the evaluation of the string immediately. As of PHP 4, eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. In case of a parse error in the evaluated code, eval() returns FALSE. In case of a fatal error in the evaluated code, the whole script exits. In PHP 3, eval() does not return a value.
[/quote]

you're not calling a return statement, so eval() isn't returning anything. try something like this:
[code]
$datoa = '$row_' . $_GET['Equipo'];
$datob = $_GET['Suceso'] . $_GET['Gorra'];
$datoc = $datoa . "['{$datob}'];";
eval("\$varold = $datoc");
$varnew = $varold + 1;
[/code]

hope this helps

Share this post


Link to post
Share on other sites
Awesome obsidian, thank you very much.

Now it works, I can get the final value. The problem I found now is updating the database. I echo'ed the result and its fine, I need to write this result to the database, here's my script:

if ((isset($_GET["MM_update"])) && ($_GET["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE $dato SET $datob=$varnew WHERE Encuentro=%s",
GetSQLValueString($datob , "int"));

mysql_select_db($database_waterpolo, $waterpolo);
$Result2 = mysql_query($updateSQL, $waterpolo) or die(mysql_error());
}

Thanks again, great helpers.


ooppps, I think I found the problem. Thank you anyway!

Was on the SQL query on WHERE=%s (just FYI)

Share this post


Link to post
Share on other sites

×

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.