[FIXED] Store PHP variable in MySQL table

Issue

I want to store two variables in a MYSQL table

--COL NAME 'details' [TEXT] --
    `$var1 = 'blah, blah'`<br>
    `$var2 = 'blah, blah, blah'`

I get the row by ID.

#MYSQLI QUERY OMITTED
$display_details  =  $row['details'];

In the HTML I have

<?php echo $display_details ?>

um dolor sit amet, consectetur adipiscing elit. Donec  `<?php echo $var1 ?>` aliquam nisl. Nullam pharetra augue sed erat lobortis lobortis. Quisque eget n

sum dolor sit ame elit. Donec  `<?php echo $var2 ?>` aliquam nisl. Nullam pharetra augue sed erat lobortis lobortis. Quisque eget n

Error is undefined variables.

--Clarification-- I want to store my variables in a table and echo them to the page.


Solution

Your best option, I think, would be to save all the variables you want into an array, serialize the array, and store the result as TEXT.

Then upon retrieval you can run an unserialize (and get back the array) and extract them.

$text = serialize(compact($var1, $var2));
// Save $text into 'details' column of database

// ...

// Another script, some times later, recovers that row and does:

extract(unserialize($row['details']));
// Now $var1 and $var2 are populated again.


Answered By - LSerni
Answer Checked By - Katrina (sql.easybugfix Volunteer)

Related Posts

Post a Comment