Forum Moderators: coopster

Message Too Old, No Replies

Storing php variable in database and retriving them

Storing php variable in database and retriving them

         

vivek avasthi

7:45 pm on May 13, 2006 (gmt 0)

10+ Year Member



Hi,

I have stored some text containg php varaible in mysql database.. now i want to retrive them. But i am getting errors. ..getting php varaibles with no value....can someone help me..

eelixduppy

7:52 pm on May 13, 2006 (gmt 0)



Welcome to WebmasterWorld!

You can get some help on basic data retrieval Here [webmasterworld.com], taken from our library.

For further help it would be necessary for you to show us what your query is and how are you managing the data retrieved.

eelix

vivek avasthi

8:20 pm on May 13, 2006 (gmt 0)

10+ Year Member



I have stored some text like this :

<?include("top.php")?>
<html>
<body>
<? echo "$username";?>

</body>
</html>

now if i retrive this text form database the value of $username is not displayed...

eelixduppy

8:22 pm on May 13, 2006 (gmt 0)



Can you post some of the code that accesses the database, please.

eelix

vivek avasthi

8:39 pm on May 13, 2006 (gmt 0)

10+ Year Member



$result=mysql_query("select textfiled from record where user_index=1");
$row=mysql_fetch_array($result);
$textfiled=stripslashes($row['textfiled']);
echo($textfield);

it displayes all the text except $username ...or any variable with $ sign present in that text...

coopster

4:37 pm on May 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The code needs to be parsed as PHP, not merely echoed to the browser. One way to accomplish this is by using PHP's eval() [php.net] function.

vivek avasthi

6:12 am on May 16, 2006 (gmt 0)

10+ Year Member



i have tried eval function ...but i am getting errors..

willybfriendly

6:21 am on May 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check that code again!

$textfiled=stripslashes($row['textfiled']);
echo($textfield);

$textfiled!= $textfield

Don't know if that was a typo when you posted, or if you cut and pasted.

WBF

vivek avasthi

6:33 am on May 16, 2006 (gmt 0)

10+ Year Member



sorry this is spelling mistake. I just want to know how can i retrive a file store in a databse with php variable and text.

coopster

3:19 pm on May 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you are getting errors then you need to figure out why and fix them. The eval should work. I'll simulate your code coming from the database result set column:
$myVariable = 'Hello World'; 
$row['textfield'] = 'I just want to say $myVariable';
$textfield=stripslashes($row['textfield']);
echo($textfield) . '<br />';
eval("\$textfield= \"$textfield\";");
echo($textfield);

Prints:
I just want to say $myVariable 
I just want to say Hello World