NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP eval()

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-22-2006, 12:15 PM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




PHP eval()


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 Code:
$certext stripslashes($row['certext']);
eval(
"$certext"); 
????: NamePros.com http://www.namepros.com/programming/179502-php-eval.html
Thats part of my PHP for getting the code and eval()ing it.

Thanks
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 03-22-2006, 12:38 PM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
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.
Peter is offline  
Old 03-22-2006, 12:43 PM THREAD STARTER               #3 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Yeah, it works but the variable just reads $variable.. if that makes sense
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 03-22-2006, 01:34 PM   #4 (permalink)
NamePros Member
Join Date: Apr 2005
Posts: 117
mikesherov will become famous soon enoughmikesherov will become famous soon enough
 



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);
mikesherov is offline  
Old 03-22-2006, 01:59 PM THREAD STARTER               #5 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




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.
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 03-25-2006, 09:43 AM THREAD STARTER               #6 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




I think it may have something to do with my host even. Every page on my website has:

PHP Code:
$page "Homepage";
include(
"head.php"); 
Then in my head.php file I have:

PHP Code:
echo "<title>$pagetitle</title>"
Yet in the browser, it displays "$pagetitle" rather than "Homepage". I know it has worked with previous hosts though.
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 03-25-2006, 03:51 PM   #7 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 38
Scott2503 is an unknown quantity at this point
 



You should do this:

PHP Code:
eval("$certext = stripslashes($row['certext']);"); 
Try that and post how it works...
Scott2503 is offline  
Old 03-26-2006, 08:03 AM THREAD STARTER               #8 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




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
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 03-26-2006, 08:07 AM   #9 (permalink)
tm
Senior Member
 
tm's Avatar
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,408
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
 



It could be something simple. try this;

Code:
$certext = stripslashes($row['certext']);
eval($certext);
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline  
Old 03-26-2006, 09:31 AM   #10 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 38
Scott2503 is an unknown quantity at this point
 



Sorry I meant:

PHP Code:
eval("$certext = stripslashes(".$row['certext'].");"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=179502
Scott2503 is offline  
Old 03-26-2006, 12:15 PM THREAD STARTER               #11 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Nah, still no worky. Not to worry. I'll try a different approach. Thanks anyway Scott
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 03-26-2006, 12:32 PM   #12 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 610
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
Originally Posted by miseria
PHP Code:
echo "<title>$pagetitle</title>"
Do this instead:
PHP Code:
echo "<title>".$pagetitle."</title>"
????: NamePros.com http://www.namepros.com/showthread.php?t=179502
__________________
ask me about the internet
Jim_ is offline  
Old 03-26-2006, 12:39 PM THREAD STARTER               #13 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Thanks Jim!
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 03-26-2006, 03:02 PM   #14 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by Scott2503
Sorry I meant:

PHP Code:
eval("$certext = stripslashes(".$row['certext'].");"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=179502
PHP Code:
eval("\$certext = stripslashes(\$row['certext']);"); 
Eric is offline  
Old 03-27-2006, 08:22 PM   #15 (permalink)
NamePros Member
 
Icespadez's Avatar
Join Date: Apr 2005
Location: Boston, MA
Posts: 26
Icespadez is an unknown quantity at this point
 



Originally Posted by miseria
I think it may have something to do with my host even. Every page on my website has:

PHP Code:
$page "Homepage";
include(
"head.php"); 
Then in my head.php file I have:

PHP Code:
echo "<title>$pagetitle</title>"
Yet in the browser, it displays "$pagetitle" rather than "Homepage". I know it has worked with previous hosts though.

Is your variable called $page or $pagetitle? If this is the code you have in your files, there is no variable named $pagetitle.
Icespadez is offline  
Old 03-27-2006, 10:43 PM   #16 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 193
2knew has a spectacular aura about2knew has a spectacular aura about
 



Jim already answered this. post deleted
2knew is offline  
Old 04-02-2006, 02:11 PM THREAD STARTER               #17 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




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.
__________________
Encenta - Amazon Associates CMS
Last edited by Encenta.com; 04-02-2006 at 02:18 PM.
Encenta.com is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:44 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger