str_replace

Discussion in 'PHP' started by crazyryan, Aug 2, 2007.

  1. #1
    I'm trying to make insert extensions and the file type they display. Using a form I want to make it easier.

    So if someone submits:
    <img src="LOCATION" />, LOCATION is replaced with $file

    I'm using:
    <?php
    include("config.php");
    if(isset($_POST['addextension'])) {
    
    $code = $_POST['code'];
    $type = $_POST['type'];
    
    
    $code = str_replace("LOCATION", " . $file . ", $code);
    
    @mysql_query("INSERT INTO `types` (code, type) VALUES ('" . $code . "', '" . $type . "')");
    
    echo "Added";
    }
    ?>
    PHP:
    Although $file is being ignored and only the dots are being inserted into the database, appreciate some help, thanks :)
     
    crazyryan, Aug 2, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Where is $file set? In config.php?
     
    krt, Aug 2, 2007 IP
  3. nagasharmi

    nagasharmi Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    just concatinate file name and extentsion

    $filename="google"
    $modifiyfilename=$filename."txt";

    ok
     
    nagasharmi, Aug 2, 2007 IP
  4. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #4
    $code = str_replace("LOCATION", $file, $code);
    Code (markup):
    Is $file being set before you try to replace "LOCATION" in the $code string? It could be that $file is blank. echo the $file before the str_replace to make sure you set the varable $file.
     
    exodus, Aug 2, 2007 IP