Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2005-07-08, 07:28 PM   #1
MadMax
"Without evil there can be no good, so it must be good to be evil sometimes" ~ Satan
 
MadMax's Avatar
 
Join Date: Aug 2004
Location: Motor City, baby, where carjacking was invented! Now GIMME THOSE SHOES!
Posts: 2,385
Need PHP Help - Losing My Mind

So I'm trying to get a little script running, and I'm beating my head against a wall. I should mention at this point that I'm a PHP newbie.

PHP 4.3
MySQL 4.0.13

This is a page of the script on which you can edit a string of HTML stored in a MySQL database, then when you hit "update" the DB field is updated and the page refreshes to display the new info.

The problem is, it's not displaying the info in the DB accurately, and the problem cascades when you repeatedly hit "update."

For a piece of test code I'm using one of my category recip tables. The code is stored in the DB accurately, but when it displays on the page it's missing the first line of code and there's an extra "> at the end that isn't in the database. When you hit "update" and the page refreshes, THAT's when the first line of code and ending "> appear in the DB, and then I lose one more line of code at the top and get one more "> at the end of the code.

When I "view source" on the page when first going to it (when the code is fresh from the DB) the first line of code is actually in the page source but not displayed on the page, and the extra "> is also in the source.

I'm sure this is something stupid that should be staring me in the face. Please help, losing my fuckin' mind here. Code is below.
PHP Code:
<?php

//Edit HTML Code
//For Admin Control Panel


// HANDLE POST METHOD
             
if (isset($_POST['submit'])) {

// Include File With Connection To  Database 
include ("inc/connect.inc");

            
// Insert New Code Info Into Database
            
            
$new_code $_POST['new_code'];

            
$new_code addslashes($new_code);
            
            
$query "UPDATE site SET template='$new_code' WHERE siteid=1";
                     
            
mysql_query($query);

// Disconnect from Database
            
include ("inc/disconnect.inc");

            echo 
"HTML Template Successfully Edited<BR><BR><BR>";
            }  

?>

<!DOCTYPE html PUBLIC 
    "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html>
<head>
<title>Edit Reciprocal Link Template - Recip Philes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<?php

// POPULATE FORM WITH DB INFO

// connect to mysql and select database

include ("inc/connect.inc");

// pull info from database and assign variable to query

$pullinfo "SELECT template FROM site WHERE siteid=1";

$result mysql_query($pullinfo);


?>


<form action="edit-recip-template.php" method="POST" >
  <p>EDIT HTML Template In Database</p>
  <p>&nbsp; </p>
  <table width="676" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td width="533"> </td>
    </tr>
    <tr> 
      <td width="533"> 
        <textarea name="new_code" rows=30 cols=70 
        value="<?php while ($info_to_edit mysql_fetch_object($result)) { 
            
$oldcode $info_to_edit->recip_template;
            
            echo 
$oldcode;
        }
        
            
?>">
        </textarea>
      </td>
    </tr>
    <tr> 
      <td width="533"> 
        <input type="submit" name="submit" value="Update Code">
      </td>
    </tr>
  </table>

</form>

<?php
// Disconnect from Database
            
include ("inc/disconnect.inc");
?>

</body>
</html>
MadMax is offline   Reply With Quote
Old 2005-07-08, 07:40 PM   #2
Toby
Lonewolf Internet Sales
 
Toby's Avatar
 
Join Date: Mar 2005
Location: Houston
Posts: 4,826
Send a message via ICQ to Toby
Do a 'view source' from your browser and check the syntax of your form. I have a suspicion that quotes or something else within the database content is messing up the textarea value.
Toby is offline   Reply With Quote
Old 2005-07-08, 07:43 PM   #3
MadMax
"Without evil there can be no good, so it must be good to be evil sometimes" ~ Satan
 
MadMax's Avatar
 
Join Date: Aug 2004
Location: Motor City, baby, where carjacking was invented! Now GIMME THOSE SHOES!
Posts: 2,385
ARRRGH! Fuckin' Newbie Mistake

THANKS TOBY

I was using the code pulled from the DB as value="code" instead of just putting it in the text area.

Sometimes you just gotta take a step back...
MadMax is offline   Reply With Quote
Old 2005-07-08, 07:44 PM   #4
Chop Smith
Eighteen 'til I Die
 
Chop Smith's Avatar
 
Join Date: Apr 2003
Location: Mississippi
Posts: 2,168
Send a message via ICQ to Chop Smith
Madmax, post a sample of html code that you are storing in your db table
__________________
Chop Smith is offline   Reply With Quote
Old 2005-07-08, 08:21 PM   #5
MadMax
"Without evil there can be no good, so it must be good to be evil sometimes" ~ Satan
 
MadMax's Avatar
 
Join Date: Aug 2004
Location: Motor City, baby, where carjacking was invented! Now GIMME THOSE SHOES!
Posts: 2,385
HTML Code:
<table width="184" border="1" bordercolor="#b02b37" bgcolor="#b02b37" height="67">
            <tr> 
              <td bordercolor="#FFFFFF" bgcolor="#FFFFFF"> 
                <div align="center"><b><font face="Georgia, Times New Roman, Times, serif"><a href="http://www.fetishphiles.com/links/amateur/index.html"><font color="b02b37" size="-1">Amateur 
                  Porn Links</font></a></font></b></div>
              </td>
            </tr>
            <tr> 
              <td bgcolor="b02b37" bordercolor="b02b37"> 
                <div align="center"><b><font face="Georgia, Times New Roman, Times, serif"><a href="http://www.fetishphiles.com"><font color="#E1E1E1" size="+1">Fetish 
                  Philes</font></a></font></b></div>
              </td>
            </tr>
            <tr> 
              <td bordercolor="#FFFFFF" height="6" bgcolor="#FFFFFF"> 
                <div align="center"><b><font face="Georgia, Times New Roman, Times, serif"><a href="http://www.fetishphiles.com/free-porn.html"><font color="b02b37" size="-1">Free 
                  Porn Links</font></a></font></b></div>
              </td>
            </tr>
          </table>
MadMax is offline   Reply With Quote
Old 2005-07-08, 09:15 PM   #6
Chop Smith
Eighteen 'til I Die
 
Chop Smith's Avatar
 
Join Date: Apr 2003
Location: Mississippi
Posts: 2,168
Send a message via ICQ to Chop Smith
So you found it?
__________________
Chop Smith is offline   Reply With Quote
Old 2005-07-08, 09:57 PM   #7
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
another thing to look out for here is the status of either magic_quotes_gpc or magic_quotes_runtime when you are using addslashes.

if _gpc is on, and the variable is posted, it will already have slashes, and if someone knows those settings they could do malicious things.

So, those settings could also add some unexpected behavior when putting ', " and other characters in form fields.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2005-07-08, 10:29 PM   #8
MadMax
"Without evil there can be no good, so it must be good to be evil sometimes" ~ Satan
 
MadMax's Avatar
 
Join Date: Aug 2004
Location: Motor City, baby, where carjacking was invented! Now GIMME THOSE SHOES!
Posts: 2,385
I found the first error, so that's set. Thanks for the help so far guys

Next problem

I'd like to select a form field containing the same HTML from eariler, insert that HTML (which uses <?php ?> tags to parse variables) from the MySQL field, then display them on a page and get PHP to actually parse the PHP tags. No luck so far. Everything parses exactly the way I want it to when I take the same data that's in the DB and use it as an included file, but when I echo the HTML from the DB after getting it with a MySQL query the PHP tags and contents are left as regular HTML (PHP doesn't parse the PHP tags).

If I'm being a pain in the ass just let me know

Making every effort to find these answers on my own....
MadMax is offline   Reply With Quote
Old 2005-07-08, 11:02 PM   #9
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
not sure I understand completely, but, eval() will evaluate php code, or, you could use obstart() and grab the output from a function if you have written it that way.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2005-07-09, 01:16 AM   #10
b1ng0
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
Join Date: Jan 2005
Posts: 85
Send a message via ICQ to b1ng0
I think he's wanting to parse and execute php code that is stored within the database, and already being included within a php page.

I have a script that I need to do the same thing so if anyone knows how it's done, we'd love to know . Unfortunately I don't think its possible MadMax .
b1ng0 is offline   Reply With Quote
Old 2005-07-09, 01:25 AM   #11
Toby
Lonewolf Internet Sales
 
Toby's Avatar
 
Join Date: Mar 2005
Location: Houston
Posts: 4,826
Send a message via ICQ to Toby
Quote:
Originally Posted by b1ng0
I think he's wanting to parse and execute php code that is stored within the database, and already being included within a php page...
That would require the server to parse the page twice, which it won't do. Another way to make it work would be to use a script to generate and save a php page on the server, then redirect to that page when done.
Toby is offline   Reply With Quote
Old 2005-07-09, 01:29 AM   #12
b1ng0
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
Join Date: Jan 2005
Posts: 85
Send a message via ICQ to b1ng0
That's what I was thinking but depending on how complex the code is he needs to run, eval() might work for him... something like

$recip = eval($recip);

Keep variable scope in mind...
b1ng0 is offline   Reply With Quote
Old 2005-07-10, 11:58 PM   #13
MadMax
"Without evil there can be no good, so it must be good to be evil sometimes" ~ Satan
 
MadMax's Avatar
 
Join Date: Aug 2004
Location: Motor City, baby, where carjacking was invented! Now GIMME THOSE SHOES!
Posts: 2,385
OK, so I got the php in the first file I was working on to parse by turning it into an included .php file instead of info in a database. One problem solved, and another emerges

Now I've got what I want displaying, but the html displayed on the page doesn't have the font attributes applied, i.e. everything shows up as default link colors, font faces, etc. When I view source on the page and copy/paste the exact same html being displayed there onto a new page and view it, it shows up fine. Anyone got any ideas? I've never had problems getting html to "parse" before....
MadMax is offline   Reply With Quote
Reply


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

Forum Jump


All times are GMT -4. The time now is 03:58 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc