Jump to content

Problem inserting PHP code into a MySQL db (joomla)


eviktore

Recommended Posts

Hi,

 

The subject might be confusing. The thing I am trying to do is that I want to create a new row in a MySQL database, and in one of the fields I want to insert some PHP code. So that i can request that field from a browser and show the result of the code.

 

The problem is that when I try to create this database entry with a php statement the variables in the code to be inserted are handled as variables in the statement trying to insert in the database. The challenge is hence to write the varibles as plain text, while they still will be regognized as variables when i request the script later. The MySQL database is actually a joomla site and the code is supposed to be the introtext of an article in jos_content.

 

The code I want to insert is the following:

 

 

<?php

// These variables are picked up by the script that is inserting
$id = explode(":", $_GET['id']);
$bo = $id['1'];


// I select the different properties from another database
$result = mysql_query("SELECT * FROM oversikt WHERE id='$bo'") or die(mysql_error());
$row = mysql_fetch_array($result);


?>
<head>


</head>
<body>
<ul>
<li>Header 1 
<ul id='he1'>
<li>Sub1: <?php echo $row['s1']; ?></li>
<li>Sub 2: <?php echo $row['s2t']; ?></li>
<li>Sub3: <?php echo $row['s3']; ?></li>
<li>Mark:
<?php 

if ($row['s4']==1) echo "Yes"; else echo "No";
?>
</li>
</ul>
</li>

</ul>
</body>

 

 

Any ideas?

Link to comment
Share on other sites

All you need to really do is put your code into a string, then insert it into the database. What exactly is the issue?

 

Why you would want to be executing code stored within a database however is beyond me.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.