PHP eval()

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

SiKing

Registered MemberEstablished Member
Impact
6
Hey, Does anyone know how to use the eval function. I wanna output a variable which is stored in a mySQL database but I keep getting this stupid error.

Parse error: syntax error, unexpected T_STRING in /home/.eurypides/npsale/vezor.net/certificate.php(39) : eval()'d code on line 1

I'm guessing there's an error in the entry in the database but i removed the text apart from the variable and still nothing.

PHP:
$certext = stripslashes($row['certext']);
eval("$certext");

Thats part of my PHP for getting the code and eval()ing it.

Thanks
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
try echoing out $certext and ensure that it is valid php code. Never used this function myself but looking at the php.net website it states that it has to be 100% valid php code.
 
0
Close
Yeah, it works but the variable just reads $variable.. if that makes sense
 
0
Close
the eval function is not what you should use to output variables. Use print() instead. The eval() function evaluates whatever string you put inside of it as PHP code:

print('hello'); //prints to the browser: hello
eval('hello'); //is equivalent to typing "hello" as that LINE OF CODE

print('$cert=2;') // prints to the browser: $cert=2;
eval('$cert=2;') // is the equivalent of typing "$cert=2;" as that LINE OF CODE

eval('$cert=2;');
print($cert);

//will print the value "2" because it is the same as saying:

$cert=2;
print($cert);
 
0
Close
I get what you're saying Mike, but it still displays "$url" in the text.

$url is the variable in the database.
$certext is the text which the variable is in.

Thanks for the help though Mike

I think it may be the way I've set it up, I set the variable $url first.

1. $url is set
2. Row ($certext) from MySQL database is taken with "$url" within the text.
3. Need to print $certext.
 
0
Close
I think it may have something to do with my host even. Every page on my website has:

PHP:
$page = "Homepage";
include("head.php");

Then in my head.php file I have:

PHP:
echo "<title>$pagetitle</title>";

Yet in the browser, it displays "$pagetitle" rather than "Homepage". I know it has worked with previous hosts though. :td:
 
0
Close
You should do this:

PHP:
eval("$certext = stripslashes($row['certext']);");

Try that and post how it works...
 
0
Close
Get the following error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/.eurypides/npsale/vezor.net/certificate.php on line 38


But thanks anyway
 
0
Close
It could be something simple. try this;

Code:
$certext = stripslashes($row['certext']);
eval($certext);
 
0
Close
Sorry I meant:

PHP:
eval("$certext = stripslashes(".$row['certext'].");");
 
0
Close
Nah, still no worky. Not to worry. I'll try a different approach. Thanks anyway Scott
 
0
Close
miseria said:
PHP:
echo "<title>$pagetitle</title>";

Do this instead:
PHP:
echo "<title>".$pagetitle."</title>";
 
0
Close
Thanks Jim! :)
 
0
Close
Scott2503 said:
Sorry I meant:

PHP:
eval("$certext = stripslashes(".$row['certext'].");");
PHP:
eval("\$certext = stripslashes(\$row['certext']);");
 
0
Close
miseria said:
I think it may have something to do with my host even. Every page on my website has:

PHP:
$page = "Homepage";
include("head.php");

Then in my head.php file I have:

PHP:
echo "<title>$pagetitle</title>";

Yet in the browser, it displays "$pagetitle" rather than "Homepage". I know it has worked with previous hosts though. :td:


Is your variable called $page or $pagetitle? If this is the code you have in your files, there is no variable named $pagetitle.
 
0
Close
Jim already answered this. post deleted
 
0
Close
I've been trying to sort this all afternoon. It is still displaying $variable. I've got rid of all the Errors but it is still not working!!

It works when there is just $variable; in the database but I need text with $variable in.
 
Last edited:
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back