[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 03-22-2006, 11:15 AM   #1 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


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");
Thats part of my PHP for getting the code and eval()ing it.

Thanks
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 03-22-2006, 11:38 AM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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, 11:43 AM   #3 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


Yeah, it works but the variable just reads $variable.. if that makes sense
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 03-22-2006, 12:34 PM   #4 (permalink)
NamePros Member
 
Join Date: Apr 2005
Posts: 116
134.00 NP$ (Donate)

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, 12:59 PM   #5 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


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.
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 03-25-2006, 08:43 AM   #6 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


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.
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 03-25-2006, 02:51 PM   #7 (permalink)
NamePros Member
 
Join Date: Oct 2005
Posts: 38
9.80 NP$ (Donate)

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, 07:03 AM   #8 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


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
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 03-26-2006, 07:07 AM   #9 (permalink)
tm
Senior Member
 
tm's Avatar
 
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,409
374.65 NP$ (Donate)

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, 08:31 AM   #10 (permalink)
NamePros Member
 
Join Date: Oct 2005
Posts: 38
9.80 NP$ (Donate)

Scott2503 is an unknown quantity at this point


Sorry I meant:

PHP Code:
eval("$certext = stripslashes(".$row['certext'].");");
Scott2503 is offline  
Old 03-26-2006, 11:15 AM   #11 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


Nah, still no worky. Not to worry. I'll try a different approach. Thanks anyway Scott
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 03-26-2006, 11:32 AM   #12 (permalink)
NamePros Regular
 
Jim_'s Avatar
 
Join Date: Aug 2005
Posts: 585
285.40 NP$ (Donate)

Jim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to all

Save The Children
Quote:
Originally Posted by miseria
PHP Code:
echo "<title>$pagetitle</title>";
Do this instead:
PHP Code:
echo "<title>".$pagetitle."</title>";
__________________
ask me about the internet
Jim_ is offline  
Old 03-26-2006, 11:39 AM   #13 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


Thanks Jim!
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 03-26-2006, 02:02 PM   #14 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Quote:
Originally Posted by Scott2503
Sorry I meant:

PHP Code:
eval("$certext = stripslashes(".$row['certext'].");");
PHP Code:
eval("\$certext = stripslashes(\$row['certext']);");
__________________
Eric is offline  
Old 03-27-2006, 07:22 PM   #15 (permalink)
NamePros Member
 
Icespadez's Avatar
 
Join Date: Apr 2005
Location: Boston, MA
Posts: 26
290.00 NP$ (Donate)

Icespadez is an unknown quantity at this point


Quote:
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, 09:43 PM   #16 (permalink)
NamePros Member
 
Join Date: Oct 2005
Posts: 191
3,301.75 NP$ (Donate)

2knew has a spectacular aura about2knew has a spectacular aura about


Jim already answered this. post deleted
2knew is offline  
Old 04-02-2006, 01:11 PM   #17 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


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.
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets

Last edited by miseria; 04-02-2006 at 01:18 PM.
miseria is offline  
Closed Thread


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 04:33 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85