Jump to content


Photo

Help with eval();


  • Please log in to reply
4 replies to this topic

#1 Julian

Julian
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 29 May 2006 - 11:02 PM

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.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 29 May 2006 - 11:31 PM

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...
~ D Kuang

#3 Julian

Julian
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 30 May 2006 - 03:38 PM

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.

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 30 May 2006 - 03:48 PM

here's part of your problem:

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.


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

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 Julian

Julian
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 30 May 2006 - 05:30 PM

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)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users